Win32com and Unicode

Gerhard Häring gh_pythonlist at gmx.de
Sun Jan 6 00:20:58 EST 2002


Le 05/01/02 à 17:52, Tim Roberts écrivit:
> I apologize if this appears twice.  As I was writing it the first time, I
> spilled nearly a liter of iced tea into my laptop.  After a quarter century
> of computing, you'd think I would know better.  Fortunately, disaster seems
> to have been averted, but you can bet I now have a COMPLETE backup...
> 
> I have a Postgres database on a Linux machine.  I'm accessing it from
> Python 2.2 on Windows via the ADODB interfaces.  Overall, this works very
> well.  However, I have one issue I can't resolve.
> 
> One of the fields in one of my tables is a last name.  One of the last
> names has an accented character (e with acute accent).  When I attempt to
> read the contents of that field, I get an exception from the __str__
> handler in the Field class generated by the Pythonwin COM Makepy utility:
> it complains  that the conversion from Unicode failed because one of the
> characters was greater than 127.
> 
> I can believe this, but I don't know how to fix it.  In Windows parlance,
> is there a way I can register a "code page" with Python so it knows how to
> convert characters beyond the lower 128?

I think you could set the default encoding scheme in your
sitecustomize.py like I described here:

http://www.faqts.com/knowledge_base/view.phtml/aid/11712/fid/562

Or you can convert manually to ISO-8859-1 using the .encode() method of
the string class.

Gerhard
-- 
mail:   gerhard <at> bigfoot <dot> de       registered Linux user #64239
web:    http://www.cs.fhm.edu/~ifw00065/    OpenPGP public key id 86AB43C0
public key fingerprint: DEC1 1D02 5743 1159 CD20  A4B6 7B22 6575 86AB 43C0
reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b')))




More information about the Python-list mailing list