Skip to content

file.readline() cannot read weird ascii character in file #59334

Closed

Description

@TonyMalykh
BPO 15129
Nosy @amauryfa
Files
  • testpy.zip
  • 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-06-21.22:05:46.376>
    created_at = <Date 2012-06-21.20:36:27.449>
    labels = ['type-bug', 'expert-IO']
    title = 'file.readline() cannot read weird ascii character in file'
    updated_at = <Date 2012-06-21.22:05:46.285>
    user = 'https://bugs.python.org/TonyMalykh'

    bugs.python.org fields:

    activity = <Date 2012-06-21.22:05:46.285>
    actor = 'amaury.forgeotdarc'
    assignee = 'none'
    closed = True
    closed_date = <Date 2012-06-21.22:05:46.376>
    closer = 'amaury.forgeotdarc'
    components = ['IO']
    creation = <Date 2012-06-21.20:36:27.449>
    creator = 'Tony.Malykh'
    dependencies = []
    files = ['26075']
    hgrepos = []
    issue_num = 15129
    keywords = []
    message_count = 2.0
    messages = ['163363', '163373']
    nosy_count = 2.0
    nosy_names = ['amaury.forgeotdarc', 'Tony.Malykh']
    pr_nums = []
    priority = 'normal'
    resolution = 'wont fix'
    stage = None
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue15129'
    versions = ['Python 2.7']

    Activity

    1. TonyMalykh commented on Jun 21, 2012

      TonyMalykhmannequin
      MannequinAuthor

      readline() or readlines() method can read the file up to the line where weird character ascii code 26 appears. I would like to read the entire file though. A simple example attached.

    2. amauryfa commented on Jun 21, 2012

      @amauryfa
      Contributor

      Your problem is similar to this discussion:
      http://stackoverflow.com/questions/405058/line-reading-chokes-on-0x1a
      On Python2, files are based on the fopen() C function, and on Windows files opened in text mode stop reading on the first character 26 (^Z, or EOF)

      The best solution here is probably to open the file in "universal" mode:
      f = open("test.txt", "rU")
      ...Or use Python3, which has a completely new implementation of the open() function.

    3. 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

      topic-IOtype-bugAn unexpected behavior, bug, or error

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions