This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: print() encodes characters to native system encoding
Type: behavior Stage:
Components: Unicode Versions: Python 3.3
process
Status: closed Resolution: duplicate
Dependencies: Superseder: windows console doesn't print or input Unicode
View: 1602
Assigned To: Nosy List: Robert.Sjöblom, ezio.melotti, loewis, pitrou
Priority: normal Keywords:

Created on 2012-03-11 16:39 by Robert.Sjöblom, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (3)
msg155393 - (view) Author: Robert Sjöblom (Robert.Sjöblom) Date: 2012-03-11 16:39
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>
   print(line)
UnicodeEncodeError: 'cp932' codec can't encode character '\xe9' in
position 13: illegal multibyte sequence

Shouldn't the output be in unicode?
msg155395 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2012-03-11 16:44
Probably a duplicate of issue1602.
msg155401 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2012-03-11 18:18
Robert: this is not a bug. Python's IO stack has the fundamental assumption that streams are byte-oriented. So the "shouldn't be the output in Unicode" is not a possible solution, since Unicode cannot work on a byte stream.

As a feature request, this is indeed a duplicate of 1602.
History
Date User Action Args
2022-04-11 14:57:27adminsetgithub: 58461
2012-03-11 18:18:17loewissetstatus: open -> closed

superseder: windows console doesn't print or input Unicode
versions: + Python 3.3, - Python 3.2
nosy: + loewis

messages: + msg155401
resolution: duplicate
2012-03-11 16:44:17pitrousetnosy: + pitrou
messages: + msg155395
2012-03-11 16:39:43Robert.Sjöblomcreate