I was trying to make a program in Python that could make changes to another .py file so I could change its code automatically. I was doing the following test in Shell before writing the program itself:
>>> import os
>>> file = open(os.path.abspath('.') + 'outroarquivo.py', 'a+')
>>> file.write("Quero caféééééééé!")
The text was very random, because it was just for testing, 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 for some accent or ç within the .write()
parameter.
Can anyone help me solve this? Maybe there is some way to change the codec?