What happened with python? messed strings?

Juergen Perlinger juergen.perlinger at t-online.de
Sun Apr 20 15:53:32 EDT 2008


algaba at droog.sdf-eu.org wrote:

> 
> Hi,
> I used extensively python and now I find this mess with strings,
> I can't even reproduce tutorial examples:
>>>> "apfel".encode('utf-8')  (it was with umlaut)
>   File "<stdin>", line 0
>     
>     ^
> SyntaxError: 'ascii' codec can't decode byte 0xc4 in position 1:
> ordinal not in range(128)
>>>> 
> Is there any good guide to this mess of codecs and hell ?
> 
> python should have stayed at version 1.5, every single 'improvement'
> has been a mess. But this is the definitive hell.
> 
> thanks!
> 

Basically you're not using ASCII encoding in your source text... You need to
define an encoding for your source if you're using german umlauts or other
fancy stuff.

See chapter 2.1.4 of the reference manual, and add e.g.

# -*- coding: utf-8 -*-

as first or second line to your script. Make sure your editor talks utf-8,
or use the encoding used by your editor. cp1552 is a good choice for
windows...

-- 
juergen 'pearly' perlinger
"It's hard to make new errors!"



More information about the Python-list mailing list