UnicodeError...
Teemu Luojola
tempe at pp.inet.fi
Mon Jul 29 15:50:10 EDT 2002
Hi,
I'm running Python 2.2.1 on Windows 95 with IDLE 0.8. When trying to use
Scandic letters ('åäö'), I get an expected error message: "UnicodeError:
ASCII encoding error: ordinal not in range(128)." This problem is dealt
in Python FAQ in chapter 4.102. and the following solution is given:
> # Set the string encoding used by the Unicode implementation.
> # The default is 'ascii'
> encoding = "ascii" # <= CHANGE THIS if you wish
>
> # Enable to support locale aware default string encodings.
> import locale
> loc = locale.getdefaultlocale()
> if loc[1]:
> encoding = loc[1]
> if encoding != "ascii":
> import sys
> sys.setdefaultencoding(encoding)
>
The problem is, that sys doesn't include setdefaultencoding(). Site.py
knows the reason for this:
> # On Non-Unicode builds this will raise an AttributeError...
Tell me, please, how to get that Unicode build.
When running Python in command line mode, there is no UnicodeError and
print 'åäö' returns the expected result: 'åäö'. Why there is such a
difference?
- Teemu Luojola
More information about the Python-list
mailing list