character encoding conversion

Christian Ergh christian.ergh at gmail.com
Mon Dec 13 11:35:25 CET 2004


- snip -
> def get_encoded(st, encodings):
>     "Returns an encoding that doesn't fail"
>     for encoding in encodings:
>         try:
>             st_encoded = st.decode(encoding)
>             return st_encoded, encoding
>         except UnicodeError:
>             pass
-snip-
This works fine, but after this you have three possible encodings (or 
even more, looking at the data in the net you'll see a lot of 
encodings...)- what we need is just one for all.
Chris



More information about the Python-list mailing list