Skip to content

print() encodes characters to native system encoding #58461

Closed

Description

@RobertSjblom
BPO 14253
Nosy @loewis, @pitrou, @ezio-melotti
Superseder
  • bpo-1602: windows console doesn't print or input Unicode
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2012-03-11.18:18:17.118>
    created_at = <Date 2012-03-11.16:39:43.676>
    labels = ['type-bug', 'expert-unicode']
    title = 'print() encodes characters to native system encoding'
    updated_at = <Date 2012-03-11.18:18:17.115>
    user = 'https://bugs.python.org/RobertSjblom'

    bugs.python.org fields:

    activity = <Date 2012-03-11.18:18:17.115>
    actor = 'loewis'
    assignee = 'none'
    closed = True
    closed_date = <Date 2012-03-11.18:18:17.118>
    closer = 'loewis'
    components = ['Unicode']
    creation = <Date 2012-03-11.16:39:43.676>
    creator = 'Robert.Sj\xc3\xb6blom'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 14253
    keywords = []
    message_count = 3.0
    messages = ['155393', '155395', '155401']
    nosy_count = 4.0
    nosy_names = ['loewis', 'pitrou', 'ezio.melotti', 'Robert.Sj\xc3\xb6blom']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = None
    status = 'closed'
    superseder = '1602'
    type = 'behavior'
    url = 'https://bugs.python.org/issue14253'
    versions = ['Python 3.3']

    Activity

    1. RobertSjblom commented on Mar 11, 2012

      RobertSjblommannequin
      MannequinAuthor

      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?

    2. pitrou commented on Mar 11, 2012

      @pitrou
      Member

      Probably a duplicate of bpo-1602.

    3. loewis commented on Mar 11, 2012

      loewismannequin
      Mannequin

      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.

    4. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions