Unicode error in exefied Python script

Tim Daneliuk tundra at tundraware.com
Mon Jan 20 11:40:07 EST 2003


Martin v. Löwis wrote:
> Tim Daneliuk <tundra at tundraware.com> writes:
> 
> 
>>        s += Name of a file
> 
> [...]
> 
>>I got the error you mentioned. After poking at it for a while, I
>>discovered that the Win32 API was returning *Unicode* strings, but all
>>my stuff was in ASCII. What was truly wierd about it is that the error
>>didn't get thrown until the last s += statement, even though the error
>>was introduced in the Win32Result statement. Python GURUS: Any idea why
>>this is??????
> 
> 
> Most likely, "Name of a file" was not an ASCII string, but a byte
> string containing non-ASCII characters. As s was already a Unicode
> object, that byte string was converted to Unicode, which failed.

Exactly right - So when concatenating strings like I did above,
Python always promotes the result to the 'higher' type?

> 
> You could also have solved this by writing
> 
>    s += unicode(Name of file, encoding that your operating system uses
>    for file names)


This too appears to work as you suggest.  Is there some portable way
to determine the codepage in use on Win32 and posix systems?


-- 
------------------------------------------------------------------------------
Tim Daneliuk
tundra at tundraware.com





More information about the Python-list mailing list