[Tutor] Unicode to string (original) (raw)

Isr Gish isrgish at fastem.com
Wed Jul 7 04:43:06 CEST 2004


I'm having problems with printing a uicode string. I'm getting an error. TypeError: Write() argument 1 must be string without null bytes, not unicode

So I was trying to convert the unicode object to a string. This is what I'm doing.

uni = u'\\x00M\x00y\x00 \x00D\x00o\x00c\x00u\x00m\x00e\x00n\x00t\x00s\x00\\x00P\x00o\x00c\x00k\x00e\x00t\x00C\x00\\x00T\x00r\x00i\x00a\x00l\x00s\x00.\x00a\x00p\x00p\x00\x00' tmp = uni.encode('mbcs') tmp = tmp.decode('utf-16', 'ignore')

Only then can I print "tmp".

All this seems to be a big mess I'm sure there must be some better way.

Any help would be aprreciated. Isr



More information about the Tutor mailing list