Python 2.7 IDLE Win32 interactive, pasted characters i- wrong encoding

Chris Angelico rosuav at gmail.com
Mon Aug 18 19:44:43 EDT 2014


Python 3 works fine, at least for BMP characters:

Python 3.4.0 (v3.4.0:04f714765c13, Mar 16 2014, 19:24:06) [MSC v.1600
32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> u"U+20AC is € is 0x80 in CP-1252"
'U+20AC is € is 0x80 in CP-1252'
>>> ascii(_)
"'U+20AC is \\u20ac is 0x80 in CP-1252'"

Python 2 doesn't:

Python 2.7.8 (default, Jun 30 2014, 16:03:49) [MSC v.1500 32 bit
(Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> # -*- coding: utf-8 -*-
>>> u"U+20AC is € is 0x80 in CP-1252"
u'U+20AC is \x80 is 0x80 in CP-1252'

The pasted-in character is encoded CP-1252 instead of being a Unicode
literal. Beginning the session with the coding cookie doesn't make any
difference; nor does the Options|Configure IDLE, General tab, Default
Source Encoding, which I have set to UTF-8. My suspicion is that both
of these will work for editing files, but not for interactive
execution.

Poking around led me to this:
http://bugs.python.org/issue4454
which pointed me to
http://bugs.python.org/issue4008
but (a) that claims to have been fixed in Jan 2009 (I first noticed
this issue in 2.7.4 dated 2013, and then I updated to 2.7.8 in case it
had been fixed), and (b) it seems to be talking about the editor, not
the interactive interpreter.

How do I get IDLE to accept Unicode in literals?

ChrisA



More information about the Python-list mailing list