unable to print Unicode characters in Python 3

jefm jef.mangelschots at gmail.com
Mon Jan 26 13:16:28 EST 2009


Hi,
while checking out Python 3, I read that all text strings are now
natively Unicode.
In the Python language reference (http://docs.python.org/3.0/reference/
lexical_analysis.html) I read that I can show Unicode character in
several ways.
"\uxxxx" supposedly allows me to specify the Unicode character by hex
number and the format  "\N{name}" allows me to specify by Unicode
name.
Neither seem to work for me.
What am I doing wrong ?

Please see error output below where I am trying to show the EURO sign
(http://www.fileformat.info/info/unicode/char/20ac/index.htm):

Python 3.0 (r30:67507, Dec  3 2008, 20:14:27) [MSC v.1500 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> print('\u20ac')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "c:\python30\lib\io.py", line 1491, in write
    b = encoder.encode(s)
  File "c:\python30\lib\encodings\cp437.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_map)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\u20ac' in
position 0: character maps to <undefined>
>>>
>>> print ("\N{EURO SIGN}")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "c:\python30\lib\io.py", line 1491, in write
    b = encoder.encode(s)
  File "c:\python30\lib\encodings\cp437.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_map)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\u20ac' in
position 0: character maps to <undefined>



More information about the Python-list mailing list