[issue14253] print() encodes characters to native system encoding

Robert Sjöblom report at bugs.python.org
Sun Mar 11 17:39:44 CET 2012

New submission from Robert Sjöblom <robert.sjoblom at gmail.com>:

I'm on a cp932-encoded system. When I read in a cp1252-file, it's read into memory properly, but when printing it, Python tries to encode the output to cp932. Here's the relevant code:

address = "C:/Path/to/file/file.ext"
with open(address, encoding="cp1252") as alpha:
  print(line, end="")

Traceback (most recent call last):
 File "C:\Python32\parser.py",
line 8, in <module>
UnicodeEncodeError: 'cp932' codec can't encode character '\xe9' in
position 13: illegal multibyte sequence

Shouldn't the output be in unicode?

components: Unicode
messages: 155393
nosy: Robert.Sjöblom, ezio.melotti
priority: normal
severity: normal
status: open
title: print() encodes characters to native system encoding
type: behavior
versions: Python 3.2

Python tracker <report at bugs.python.org>

More information about the Python-bugs-list mailing list