Re: [Tutor] Encode problem

2009-05-05 Thread Mark Tolonen
"Kent Johnson" wrote in message news:1c2a2c590905050337j1afc177ene64f800dcc3a7...@mail.gmail.com... On Tue, May 5, 2009 at 1:14 AM, Mark Tolonen wrote: > The below works. ConfigParser isn't written to support Unicode > correctly. I > was able to get Unicode sections to write out, but it wa

Re: [Tutor] Encode problem

2009-05-05 Thread Kent Johnson
On Tue, May 5, 2009 at 1:14 AM, Mark Tolonen wrote: > The below works.  ConfigParser isn't written to support Unicode correctly. I > was able to get Unicode sections to write out, but it was just luck. Unicode > keys and values break as the OP discovered.  So treat everything as byte > strings:

Re: [Tutor] Encode problem

2009-05-04 Thread Mark Tolonen
"spir" wrote in message news:20090501220601.31891...@o... Le Fri, 1 May 2009 15:19:29 -0300, "Pablo P. F. de Faria" s'exprima ainsi: 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 sa

Re: [Tutor] Encode problem

2009-05-04 Thread Kent Johnson
On Mon, May 4, 2009 at 3:54 PM, Sander Sweers wrote: > 2009/5/4 Kent Johnson : >> str.decode() converts a string to a unicode object. unicode.encode() >> converts a unicode object to a (byte) string. Both of these functions >> take the encoding as a parameter. When Python is given a string, but >>

Re: [Tutor] Encode problem

2009-05-04 Thread Sander Sweers
2009/5/4 Kent Johnson : > str.decode() converts a string to a unicode object. unicode.encode() > converts a unicode object to a (byte) string. Both of these functions > take the encoding as a parameter. When Python is given a string, but > it needs a unicode object, or vice-versa, it will encode or

Re: [Tutor] Encode problem

2009-05-04 Thread spir
Le Mon, 4 May 2009 11:09:25 -0300, "Pablo P. F. de Faria" s'exprima ainsi: > 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()

Re: [Tutor] Encode problem

2009-05-04 Thread Kent Johnson
On Mon, May 4, 2009 at 1:32 PM, Pablo P. F. de Faria wrote: > Hi, all. > > I've found something that worked for me, but I'm not sure of its > secureness. The solution is: > > reload(sys) > sys.setdefaultencoding('utf-8') > > That's exactly what I wanted to do, but is this good practice? No. You s

Re: [Tutor] Encode problem

2009-05-04 Thread Kent Johnson
On Mon, May 4, 2009 at 10:09 AM, Pablo P. F. de Faria wrote: > 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). Yes, I understand that. Python has two diffe

Re: [Tutor] Encode problem

2009-05-04 Thread Pablo P. F. de Faria
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.

Re: [Tutor] Encode problem

2009-05-04 Thread Pablo P. F. de Faria
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 applica

Re: [Tutor] Encode problem

2009-05-01 Thread Kent Johnson
On Fri, May 1, 2009 at 4:54 PM, Pablo P. F. de Faria 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.

Re: [Tutor] Encode problem

2009-05-01 Thread spir
Le Fri, 1 May 2009 15:19:29 -0300, "Pablo P. F. de Faria" s'exprima ainsi: > 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 directo

Re: [Tutor] Encode problem

2009-05-01 Thread Kent Johnson
On Fri, May 1, 2009 at 2:19 PM, Pablo P. F. de Faria wrote: > 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 exp

[Tutor] Encode problem

2009-05-01 Thread Pablo P. F. de Faria
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