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

Re: [Tutor] encode unicode strings from pysqlite

2008-04-14 Thread Dinesh B Vadhia
tly! - Original Message - From: Kent Johnson To: Dinesh B Vadhia Cc: tutor@python.org Sent: Monday, April 14, 2008 3:42 AM Subject: Re: [Tutor] encode unicode strings from pysqlite Dinesh B Vadhia wrote: > Here is a program that SELECT's from a pysqlite database table

Re: [Tutor] encode unicode strings from pysqlite

2008-04-14 Thread Kent Johnson
Dinesh B Vadhia wrote: > Here is a program that SELECT's from a pysqlite database table and > encode's the returned unicode strings: > query = "SELECT fieldB FROM testDB WHERE fieldB LIKE '%s' LIMIT '%s'" > %(q, limit) > for row in cur.execute(query): Here row is a list containing a single unic

[Tutor] encode unicode strings from pysqlite

2008-04-14 Thread Dinesh B Vadhia
Here is a program that SELECT's from a pysqlite database table and encode's the returned unicode strings: import sys import os import sqlite3 con = sqlite3.connect("testDB.db") cur = con.cursor() a = u'99 Cycling Swords' b = a.encode('utf-8') print b q = '%wor%' limit = 25 query = "SELECT fiel

Re: [Tutor] encode

2006-04-18 Thread Danny Yoo
On Wed, 19 Apr 2006, kakada wrote: > I wonder if we can check the encoding of text in one text file. user is > free to encode the file whether Latin1, utf-8, ANSI... In the general case, this is difficult, and "solving" it might be worse than not. See: http://www.joelonsoftware.com/art

Re: [Tutor] encode

2006-04-18 Thread Python
On Wed, 2006-04-19 at 10:10 +0700, kakada wrote: > Hi again folks, > > I wonder if we can check the encoding of text in one text file. > user is free to encode the file whether Latin1, utf-8, ANSI... > Any ideas? def decode_file(filepath): '''Order of codecs is important. ASCII is most r

[Tutor] encode

2006-04-18 Thread kakada
Hi again folks, I wonder if we can check the encoding of text in one text file. user is free to encode the file whether Latin1, utf-8, ANSI... Any ideas? Thx da ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] encode question!

2005-09-27 Thread 铁石
tutor-request Thanks Ziyad.You answer is exactly the realson it is! I am missdirect by the coding of the html. the %25 in the url is the '%' char in file name. after urllib.unquote('xvg_h%25202.jpg') 'xvg_h%202.jpg' That's the real filename I want! thanks too, Danny Yoo! >This has n

Re: [Tutor] encode question!

2005-09-27 Thread ZIYAD A. M. AL-BATLY
On Tue, 2005-09-27 at 14:01 +0800, 铁石 wrote: > I am trying to write a stript that extract jpg files > from a html I had downloaded.I encounter a problem with > a Big5 charset html file.Big5 used in Hongkong ans Taiwan. > In this html file there's a jpg names "xvg_h%202.jpg" > in vi ,the

Re: [Tutor] encode question!

2005-09-26 Thread Danny Yoo
On Tue, 27 Sep 2005, [GB2312] ��ʯ wrote: > I am trying to write a stript that extract jpg files > from a html I had downloaded.I encounter a problem with > a Big5 charset html file.Big5 used in Hongkong ans Taiwan. > In this html file there's a jpg names "xvg_h%202.jpg" in vi ,the tag

[Tutor] encode question!

2005-09-26 Thread 铁石
I am trying to write a stript that extract jpg files from a html I had downloaded.I encounter a problem with a Big5 charset html file.Big5 used in Hongkong ans Taiwan. In this html file there's a jpg names "xvg_h%202.jpg" in vi ,the tag of the image is