Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Let's fire up the old standby, IDLE, and see if we can replicate what you're seeing.</p> <pre><code>IDLE 1.1.4 &gt;&gt;&gt; a = u'può essere / sarà / 日本' Unsupported characters in input &gt;&gt;&gt; a = u'pu\xf2 essere / sar\xe0 / \u65e5\u672c' &gt;&gt;&gt; b = a.encode('utf-8') &gt;&gt;&gt; a u'pu\xf2 essere / sar\xe0 / \u65e5\u672c' &gt;&gt;&gt; b 'pu\xc3\xb2 essere / sar\xc3\xa0 / \xe6\x97\xa5\xe6\x9c\xac' &gt;&gt;&gt; print a può essere / sarà / 日本 &gt;&gt;&gt; print b può essere / sarà / 日本 </code></pre> <p>Note that I see something different when I print <code>b</code>. This is because my shell (IDLE) does not interpret a sequence of bytes as UTF-8 text, but rather uses my platform character encoding, cp1252.</p> <p>Let's just double check this.</p> <pre><code>&gt;&gt;&gt; import sys &gt;&gt;&gt; sys.stdout.encoding 'cp1252' </code></pre> <p>Yup, that's why I get different behavior than you do. Because your sys.stdout.encoding is UTF-8. And that is why, despite <code>a</code> and <code>b</code> being completely different values, they display the same; your terminal interprets bytes as UTF-8.</p> <p>So you might be wondering if we can convert our sequence of unicode characters <code>a</code> into a sequence of bytes that can be displayed in IDLE</p> <pre><code>&gt;&gt;&gt; c = a.encode('cp1252') Traceback (most recent call last): File "&lt;pyshell#19&gt;", line 1, in -toplevel- c = a.encode('cp1252') #uses default encoding File "C:\Python24\lib\encodings\cp1252.py", line 18, in encode return codecs.charmap_encode(input,errors,encoding_map) UnicodeEncodeError: 'charmap' codec can't encode characters in position 20-21: character maps to &lt;undefined&gt; </code></pre> <p>The answer is no; <a href="http://en.wikipedia.org/wiki/Windows-1252" rel="nofollow">cp1252</a> does not support encoding Chinese characters as bytes.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload