简体   繁体   English

带有特殊字符py2exe的文件夹

[英]Folder with special characters py2exe

In my code, I call a file that is located in a folder called "Física" (please note that the "i" is acute). 在我的代码中,我调用了一个位于“Física”文件夹中的文件(请注意,“ i”是急号)。

I don't have any problem running this in my IDE (Spyder), but after I turn my program into an executable with py2exe I get an error: 我在IDE(Spyder)中运行此程序没有任何问题,但是在将程序转换为py2exe可执行文件后,出现错误:

"UnicodeEncodeError: 'ascii' codec can't encode character u'\xed'"

The problem is because of these special characters. 问题是由于这些特殊字符。 How can I solve this problem? 我怎么解决这个问题?

I tried to do the following 我尝试执行以下操作

path = unicode(path).encode('utf-8')

to treat the path with utf-8 encoding. 用utf-8编码处理路径。 But if I do this my path will be: 但是,如果我这样做,我的道路将是:

F\\xc3\\xadsica instead of Física F\\xc3\\xadsica代替Física

I found out what I was doing wrong: 我发现自己做错了什么:

I wanted to read a file from that path, and then write a file to the same path. 我想从该路径读取文件,然后将文件写入相同的路径。 I was encoding the path in utf-8 when saving it in a variable. 将路径保存在变量中时,我在utf-8中对其进行编码。 However, I was not using the decode when using that variable to write in the path. 但是,在使用该变量写入路径时,我没有使用解码。

I need to use ´encode('utf-8')´ when saving the path to a variable and then use ´decode('utf-8')´ when setting the destination path. 将路径保存到变量时,我需要使用“ encode('utf-8')”,然后在设置目标路径时使用“ decode('utf-8')”。 Thank you so much and sorry for the poor explanation 非常感谢,对不起您的解释

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM