[Pythonmac-SIG] Newbie: Unicode in Python 2.3?
Bob Ippolito
bob at redivi.com
Sat Mar 20 13:29:07 EST 2004
On Mar 20, 2004, at 12:56 PM, Philippe de Rochambeau wrote:
> I am trying to use Unicode with the Macosx 10.3 built-in Python 2.3
> interpreter. However, I keep getting messages telling me that the
> character value is not within the right range (128)
>
> >>> import codecs
> >>> alef = unichr(1488)
> >>> print alef
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> UnicodeEncodeError: 'ascii' codec can't encode character '\u5d0' in
> position 0: ordinal not in range(128)
> >>>
>
> How can you find out if a particular version of Python supports
> Unicode or not?
It supports unicode just fine, it just doesn't know your terminal does.
Terminal.app is UTF-8 by default. Try this:
Python 2.3 (#1, Sep 13 2003, 00:49:11)
[GCC 3.3 20030304 (Apple Computer, Inc. build 1495)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys, codecs
>>> sys.stdout = codecs.getwriter('utf8')(sys.stdout)
>>> print unichr(1488)
א
If you want to type UTF-8 into the terminal, you would use something
similar with getreader and sys.stdin.
-bob
More information about the Pythonmac-SIG
mailing list