[issue12632] Windows GPF with Code Page 65001

STINNER Victor report at bugs.python.org
Tue Jul 26 16:32:25 CEST 2011


STINNER Victor <victor.stinner at haypocalc.com> added the comment:

>  All I'm trying to do is run different versions of Python on the same machine from the command line.
> Some code inside Python now "break" if Python 3.1 is started with Code Page 65001.

Yes, this issue can be seen as a regression introduced in Python 3.

> I fully understand the change between Python 2.7 and 3.1 were probably due to trying to fix issue #1602 (or some other related issue).

Python 2 and 3 are very different. In Python 2, print "abc" writes a 
byte string to stdout, whereas print("abc") writes a Unicode string to 
stdout. Byte strings and character strings are two different things ;-)

Python 3 now uses Unicode by default and it requires a codec to encode 
strings to stdout. If your program don't output anything to stdout, use 
pythonw.exe instead of python.exe.

The issue #1602 is not specific to Python 3: Python 2 is unable to 
display correctly Unicode strings in the Windows console. It's less 
important in Python 2, because most developers use the default string 
type which is a byte string.

> Setting my cmd.exe code page to 65001 shouldn't mean a thing to Python if it can't associate it with an encoding.  It could, at least, just switch to 7-Bit ASCII and proceed on.  That would be better than failing!

I don't like this idea. In Python, we try to not ignore errors, but try 
instead to fix them or at least fail with an error message (the user is 
responsible to fix it or use a workaround). To fix this issue, we have 
to implement a cp65001 codec for Python or to work directly in Unicode 
using WriteConsole.

If you cannot help to implement one of this option, you can use a 
workaround:

  - don't change the codepage
  - use PYTHONIOENCODING=utf-8

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue12632>
_______________________________________


More information about the Python-bugs-list mailing list