Reputation: 260
In my code, I call a file that is located in a folder called "Física" (please note that the "i" is acute).
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:
"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. But if I do this my path will be:
F\xc3\xadsica
instead of Física
Upvotes: 0
Views: 499
Reputation: 260
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. 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. Thank you so much and sorry for the poor explanation
Upvotes: 1