Characters in Python
johnroth at ameritech.net
Thu Jun 5 17:50:56 CEST 2003
"Jan Sundström" <jansun at home.se> wrote in message
news:aaf09156.0306050423.21b45f6 at posting.google.com...
> This is a newbie question, but...
> I just downloaded Pyton 2.2.2 for Windows and started exploring it.
> I installed it so I can use TextPad or IDLE 0.8 with it and all ran
> just fine, until I started to write strings with scandinavian
> characters in them.
> >>> str = 'åäö'
> UnicodeError: ASCII encoding error: ordinal not in range(128)
> It works fine in a DOS console window or run from TextPad if I do
> something like
> str = 'Åäö'
> print str
> Python, or perhaps IDLE rather, doesn't seem toaccept characters with
> codes over 127.
> Is there a simple way to turn off this obscession with 7-bit ASCII?
> And how can one easily change what Python considers to be
> default character encoding?
> I couldn't find anything about that in the tutorial.
You need to create a unicode string. Note the 'u' in front of
the string quote. You may also need to specify a character set for your
source as a parameter when you invoke Python.
theStr = u"Åäö"
More information about the Python-list