right adjusted strings containing umlauts

Kurt Mueller kurt.alfred.mueller at gmail.com
Thu Aug 8 12:16:40 EDT 2013


Am 08.08.2013 17:44, schrieb Peter Otten:
> Kurt Mueller wrote:
>> What do I do, when input_strings/output_list has other codings like
>> iso-8859-1?
> 
> You have to know the actual encoding. With that information it's easy:
>>>> output_list
> ['\xc3\xb6', '\xc3\xbc', 'i', 's', 'f']
>>>> encoding = "utf-8"
>>>> output_list = [s.decode(encoding) for s in output_list]
>>>> print output_list
> [u'\xf6', u'\xfc', u'i', u's', u'f']

How do I get to know the actual encoding?
I read from stdin. There can be different encondings.
Usually utf8 but also iso-8859-1/latin9 are to be expected.
But sys.stdin.encoding sais always 'None'.


TIA
-- 
Kurt Mueller



More information about the Python-list mailing list