1
I was trying to make a program in Python that could make changes to another . py file in order to change its code automatically. I went to do the following test on Shell before writing the program itself:
>>> import os
>>> file = open(os.path.abspath('.') + 'outroarquivo.py', 'a+')
>>> file.write("Quero caféééééééé!")
The text was quite random, because it was only to test, but this last line gave the following return:
Traceback (most recent call last):
File "<pyshell#37>", line 1, in <module>
file.write("Quero caféééééééé!")
UnicodeEncodeError: 'cp932' codec can't encode character '\xe9' in position 9: illegal multibyte sequence
This occurs whenever I try to put some accent or ç within the parameter of .write()
.
Can anyone help me solve this? Maybe there is some way to change the codec?
Search stackoverflow in English- these accentuation questions often appear. And above all, read http://local.joelonsoftware.com/wiki/O_M%C3%Adnimo_absoluto_que_todos_programmeres_de_software_they need,_Absolutely,Positivamente_de_Saber_Sobre_Unicode_e_Conjuntos_de_Caracteres(Apologies!)
– jsbueno