<br><br><div class="gmail_quote">On Mon, Jan 26, 2009 at 1:16 PM, jefm <span dir="ltr"><<a href="mailto:jef.mangelschots@gmail.com">jef.mangelschots@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi,<br>
while checking out Python 3, I read that all text strings are now<br>
natively Unicode.<br>
In the Python language reference (<a href="http://docs.python.org/3.0/reference/lexical_analysis.html" target="_blank">http://docs.python.org/3.0/reference/<br>
lexical_analysis.html</a>) I read that I can show Unicode character in<br>
several ways.<br>
"\uxxxx" supposedly allows me to specify the Unicode character by hex<br>
number and the format  "\N{name}" allows me to specify by Unicode<br>
name.<br>
Neither seem to work for me.<br>
What am I doing wrong ?<br>
<br>
Please see error output below where I am trying to show the EURO sign<br>
(<a href="http://www.fileformat.info/info/unicode/char/20ac/index.htm" target="_blank">http://www.fileformat.info/info/unicode/char/20ac/index.htm</a>):<br>
<br>
Python 3.0 (r30:67507, Dec  3 2008, 20:14:27) [MSC v.1500 32 bit<br>
(Intel)] on win32<br>
Type "help", "copyright", "credits" or "license" for more information.<br>
>>> print('\u20ac')<br>
Traceback (most recent call last):<br>
  File "<stdin>", line 1, in <module><br>
  File "c:\python30\lib\io.py", line 1491, in write<br>
    b = encoder.encode(s)<br>
  File "c:\python30\lib\encodings\cp437.py", line 19, in encode<br>
    return codecs.charmap_encode(input,self.errors,encoding_map)[0]<br>
UnicodeEncodeError: 'charmap' codec can't encode character '\u20ac' in<br>
position 0: character maps to <undefined><br>
>>><br>
>>> print ("\N{EURO SIGN}")<br>
Traceback (most recent call last):<br>
  File "<stdin>", line 1, in <module><br>
  File "c:\python30\lib\io.py", line 1491, in write<br>
    b = encoder.encode(s)<br>
  File "c:\python30\lib\encodings\cp437.py", line 19, in encode<br>
    return codecs.charmap_encode(input,self.errors,encoding_map)[0]<br>
UnicodeEncodeError: 'charmap' codec can't encode character '\u20ac' in<br>
position 0: character maps to <undefined><br>
<font color="#888888">--<br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank"></a></font></blockquote><div><br><br>The strings are represented internally as Unicode, but you can't print them that way. When you call print(), python needs to turn your string into a sequence of bytes that are then interpreted by the terminal (in your case cmd.exe). On modern Unix-based systems (like Mac and Linux), the console uses UTF-8. Since it uses a unicode-based encoding, everything prints fine. Your Windows machine seems determined to use the old (c. 1980s) CP 437. Code Page 437 doesn't have the Euro symbol, so python throws an error. Try using "\N{EURO SIGN}".encode("cp1252"). If your console still can't handle it, you'll need to change its encoding.<br>
</div></div>