Skip to content

Truncate method #80459

Closed
Closed

Description

@CavadSalmanov
BPO 36278
Nosy @serhiy-storchaka, @tirkarthi
Superseder
  • bpo-26158: File truncate() not defaulting to current position as documented
  • 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 2019-03-13.03:41:28.172>
    created_at = <Date 2019-03-13.02:33:34.110>
    labels = ['type-bug', '3.7']
    title = 'Truncate method'
    updated_at = <Date 2019-03-13.03:41:28.171>
    user = 'https://bugs.python.org/CavadSalmanov'

    bugs.python.org fields:

    activity = <Date 2019-03-13.03:41:28.171>
    actor = 'josh.r'
    assignee = 'none'
    closed = True
    closed_date = <Date 2019-03-13.03:41:28.172>
    closer = 'josh.r'
    components = []
    creation = <Date 2019-03-13.02:33:34.110>
    creator = 'Cavad Salmanov'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 36278
    keywords = []
    message_count = 2.0
    messages = ['337830', '337831']
    nosy_count = 3.0
    nosy_names = ['serhiy.storchaka', 'xtreak', 'Cavad Salmanov']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'resolved'
    status = 'closed'
    superseder = '26158'
    type = 'behavior'
    url = 'https://bugs.python.org/issue36278'
    versions = ['Python 3.7']

    Activity

    1. CavadSalmanov commented on Mar 13, 2019

      CavadSalmanovmannequin
      MannequinAuthor

      I created a new file for researching truncate() method. and I writed this text:
      alma
      armud
      heyva
      nar
      qarpiz
      yemis

      I wanted to delete all the text apart from first line by truncate method.

      I writed these codes on python idle:
      __________________________________________
      #First, I read text for showing it's content
      >>> dosya = open('deneme.txt','r')
      >>> dosya.read()
      'alma\narmud\nheyva\nnar\nqarpiz\nyemis'
      >>> dosya.close()
      
      
      #Then writing codes for operation which I wanted
      >>> dosya = open('deneme.txt','r+')
      >>> dosya.readline()
      'alma\n'
      >>> dosya.tell()
      6
      >>> dosya.truncate()
      38
      >>> dosya.seek(0)
      0
      >>> dosya.read()
      'alma\narmud\nheyva\nnar\nqarpiz\nyemis'
      >>> dosya.close()
      #I thought I must closed the file, then read again:
      
      
      #Then I saw nothing has changed
      >>> dosya = open('deneme.txt','r')
      >>> dosya.read()
      'alma\narmud\nheyva\nnar\nqarpiz\nyemis'
      >>> dosya.close()
      
      #But when I writed codes in this way, it is worked
      >>> dosya = open('deneme.txt','r+')
      >>> dosya.readline()
      'alma\n'
      >>> dosya.tell()
      6
      >>> dosya.seek(6)
      6
      >>> dosya.truncate()
      6
      >>> dosya.close()
      >>> dosya = open('deneme.txt','r')
      >>> dosya.read()
      'alma\n'

      # I was on 6th byte in both. But it is worked which I used seek() #method. I think both of them were returnden same things

    2. tirkarthi commented on Mar 13, 2019

      @tirkarthi
      Member

      This looks like a similar report to bpo-26158 where truncate refers to the position of the underlying buffer and could be documented better.

    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

      3.7 (EOL)end of lifetype-bugAn unexpected behavior, bug, or error

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions