[Tutor] Encode problem

Pablo P. F. de Faria pablofaria at gmail.com
Fri May 1 20:19:29 CEST 2009


Hi, all. I need some help.

I'm trying to save a configuration file, using ConfigParser. The code
is the following:

self.cfg.write(codecs.open(self.properties_file,'w','utf-8'))

As one can see, the character encoding is explicitly UTF-8. But
ConfigParser keeps trying to save it as a 'ascii' file and gives me
error for directory-names containing >128 code characters (like "Á").
It is just a horrible thing to me, for my app will be used mostly by
brazillians.

What can I do? I tried everything (encode/decode). The only solution
I've found until now is to change the "site.py" file
(sys.setdefaultencoding('utf-8'), but I can't do that for every
machine that will run my app... So, there must be another way. What is
strange for me is that the File object is explicit about the encoding.
Another info: while running my app inside Eclipse this erros does not
occur.

Platforms tested: Ubuntu 8.04 and Windows XP SP3 (Python 2.5)

Any ideas?

Thanks.

-- 
---------------------------------
"Estamos todos na sarjeta, mas alguns de nós olham para as estrelas."
(Oscar Wilde)
---------------------------------
Pablo Faria
pablofaria at gmail.com


More information about the Tutor mailing list