problem with unicode

andreas.profous at googlemail.com andreas.profous at googlemail.com
Fri Apr 25 07:15:55 EDT 2008


Hi everybody,

I'm using the win32 console and have the following short program
excerpt

# media is a binary string (mysql escaped zipped file)

>> print media
xワユロ[ヨ
...
(works)

>> print unicode(media)
UnicodeDecodeError: 'ascii' codec can't decode byte 0x9c in position
1: ordinal not in range(128)
(ok i guess print assumes you want to print to ascii)

>> print unicode(media).encode('utf-8')
UnicodeDecodeError: 'ascii' codec can't decode byte 0x9c in position
1: ordinal not in range(128)
(why does this not work?)

# mapString is a unicode string (i think at least)
>> print "'" + mapString + "'"
' yu_200703_hello\ 831 v1234.9874 '

>>    mystr = "%s %s" % (mapString, media)
UnicodeDecodeError: 'ascii' codec can't decode byte 0x9c in position
1: ordinal not in range(128)

>> mystr = "%s %s" % (mapString.encode('utf-8'), media.encode('utf-8'))
UnicodeDecodeError: 'ascii' codec can't decode byte 0x9c in position
1: ordinal not in range(128)

I don't know what to do. I just want to concatenate two string where
apparently one is a binary string, the other one is a unicode string
and I always seem to get this error.

Any help is appreciated :)


More information about the Python-list mailing list