Totally confused by Python's string thing.

Doru-Catalin Togea doru-cat at ifi.uio.no
Tue Dec 17 02:11:07 EST 2002


> > So what is my problem, actually?
>
> you're trying to encode a string that's already encoded.  to do this, Python
> tries to *decode* it first, using the default encoding (ASCII).

I see!

> > 2) How do I set up my system to deal correctly and robustly with the ISO
> > 8859-1 character set? How about the ISO 8859-2 character set?
>
> convert all text to Unicode strings on the way in, and to the appropriate
> encoding on the way out.
>
> to convert from encoded data to Unicode text, use:
>
>     txt = raw.decode(encoding)
>
> or
>
>     txt = unicode(raw, encoding)
>
> to convert from Unicode text to encoded data, use:
>
>     raw = txt.encode(encoding)
>
> (where "raw" is an encoded string, and "txt" is a unicode string)

Thanks, this helped. I could fix my current situation. I'll have to do
some more studying and maybe re-write some of my routines in the future.

Thanks also for pointers to docs, and for answering so quickly.

Catalin




	<<<< ================================== >>>>
	<<     We are what we repeatedly do.      >>
	<<  Excellence, therefore, is not an act  >>
	<<             but a habit.               >>
	<<<< ================================== >>>>




More information about the Python-list mailing list