[issue36278] Truncate method
Cavad Salmanov
report at bugs.python.org
Tue Mar 12 22:33:34 EDT 2019
New submission from Cavad Salmanov <cavad2013 at gmail.com>:
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
----------
messages: 337830
nosy: Cavad Salmanov
priority: normal
severity: normal
status: open
title: Truncate method
type: behavior
versions: Python 3.7
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue36278>
_______________________________________
More information about the Python-bugs-list
mailing list