Skip to content

file.write() after file.read() adds text to the end of the file #70103

Closed

Description

@AdamWasik
mannequin
BPO 25915
Superseder
  • bpo-12215: TextIOWrapper: issues with interlaced read-write
  • 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 2015-12-20.09:55:38.642>
    created_at = <Date 2015-12-20.09:44:25.956>
    labels = ['type-bug', 'expert-IO']
    title = 'file.write() after file.read() adds text to the end of the file'
    updated_at = <Date 2015-12-20.09:56:50.377>
    user = 'https://bugs.python.org/AdamWasik'

    bugs.python.org fields:

    activity = <Date 2015-12-20.09:56:50.377>
    actor = 'SilentGhost'
    assignee = 'none'
    closed = True
    closed_date = <Date 2015-12-20.09:55:38.642>
    closer = 'Adam Wasik'
    components = ['IO']
    creation = <Date 2015-12-20.09:44:25.956>
    creator = 'Adam Wasik'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 25915
    keywords = []
    message_count = 2.0
    messages = ['256756', '256758']
    nosy_count = 1.0
    nosy_names = ['Adam Wasik']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'resolved'
    status = 'closed'
    superseder = '12215'
    type = 'behavior'
    url = 'https://bugs.python.org/issue25915'
    versions = ['Python 3.5']

    Activity

    1. AdamWasik commented on Dec 20, 2015

      AdamWasikmannequin
      MannequinAuthor
      >>> file = open(r"C:\adam.txt","r+")
      >>> file.read()
      'TEXT TEXT TEXT TEXT TEXT TEXT TEXT\nTEXT TEXT TEXT TEXT TEXT TEXT TEXT\nTEXT TE
      XT TEXT TEXT TEXT TEXT TEXT\nTEXT TEXT TEXT TEXT TEXT TEXT TEXT\nTEXT TEXT TEXT
      TEXT TEXT TEXT TEXT\nTEXT TEXT TEXT TEXT TEXT TEXT TEXT'
      >>> file.seek(0,0)
      0
      >>> file.read(1)
      'T'
      >>> file.tell()
      1
      >>> file.write("NEW")
      3
      >>> file.tell() # Why 217 rather than 4. Text is added at the end file
      217
      >>>
    2. AdamWasik commented on Dec 20, 2015

      AdamWasikmannequin
      MannequinAuthor

      duplicate of the issue bpo-12215

    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