Here is the traceback, after the last change you sugested: Traceback (most recent call last): File "/home/pablo/workspace/E-Dictor/src/MainFrame.py", line 1057, in OnClose self.SavePreferences() File "/home/pablo/workspace/E-Dictor/src/MainFrame.py", line 1069, in SavePreferences self.cfg.write(codecs.open(self.properties_file,'w','utf-8')) File "/usr/lib/python2.5/ConfigParser.py", line 373, in write (key, str(value).replace('\n', '\n\t'))) File "/usr/lib/python2.5/codecs.py", line 638, in write return self.writer.write(data) File "/usr/lib/python2.5/codecs.py", line 303, in write data, consumed = self.encode(object, self.errors) UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 27: ordinal not in range(128)
So, in "str(value)" the content is a folder name with an accented character (Á). 2009/5/4 Pablo P. F. de Faria <pablofa...@gmail.com>: > Thanks, Kent, but that doesn't solve my problem. In fact, I need > ConfigParser to work with non-ascii characters, since my App may run > in "latin-1" environments (folders e files names). I must find out why > the str() function in the module ConfigParser doesn't use the encoding > defined for the application (# -*- coding: utf-8 -*-). The rest of the > application works properly with utf-8, except for ConfigParser. What I > found out is that ConfigParser seems to make use of the configuration > in Site.py (which is set to 'ascii'), instead of the configuration > defined for the App (if I change . But this is very problematic to > have to change Site.py in every computer... So I wonder if there is a > way to replace the settings in Site.py only for my App. > > 2009/5/1 Kent Johnson <ken...@tds.net>: >> On Fri, May 1, 2009 at 4:54 PM, Pablo P. F. de Faria >> <pablofa...@gmail.com> wrote: >>> Hi, Kent. >>> >>> The stack trace is: >>> >>> Traceback (most recent call last): >>> File "/home/pablo/workspace/E-Dictor/src/MainFrame.py", line 1057, in >>> OnClose >>> self.SavePreferences() >>> File "/home/pablo/workspace/E-Dictor/src/MainFrame.py", line 1068, >>> in SavePreferences >>> self.cfg.set(u'File Settings',u'Recent files', >>> unicode(",".join(self.recent_files))) >>> UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position >>> 12: ordinal not in range(128) >>> >>> The "unicode" function, actually doesn't do any difference... The >>> content of the string being saved is "/home/pablo/Área de >>> Trabalho/teste.xml". >> >> OK, this error is in your code, not the ConfigParser. The problem is with >> ",".join(self.recent_files) >> >> Are the entries in self.recent_files unicode strings? If so, then I >> think the join is trying to convert to a string using the default >> codec. Try >> >> self.cfg.set('File Settings','Recent files', >> ','.join(name.encode('utf-8') for name in self.recent_files)) >> >> Looking at the ConfigParser.write() code, it wants the values to be >> strings or convertible to strings by calling str(), so non-ascii >> unicode values will be a problem there. I would use plain strings for >> all the interaction with ConfigParser and convert to Unicode yourself. >> >> Kent >> >> PS Please Reply All to reply to the list. >> > > > > -- > --------------------------------- > "Estamos todos na sarjeta, mas alguns de nós olham para as estrelas." > (Oscar Wilde) > --------------------------------- > Pablo Faria > Mestrando em Aquisição de Linguagem - IEL/Unicamp > Bolsista técnico FAPESP no Projeto Padrões Rítmicos e Mudança Lingüística > (19) 3521-1570 > http://www.tycho.iel.unicamp.br/~pablofaria/ > pablofa...@gmail.com > -- --------------------------------- "Estamos todos na sarjeta, mas alguns de nós olham para as estrelas." (Oscar Wilde) --------------------------------- Pablo Faria Mestrando em Aquisição de Linguagem - IEL/Unicamp Bolsista técnico FAPESP no Projeto Padrões Rítmicos e Mudança Lingüística (19) 3521-1570 http://www.tycho.iel.unicamp.br/~pablofaria/ pablofa...@gmail.com _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor