This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author fornax
Recipients fornax
Date 2016-01-19.15:19:44
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1453216784.99.0.234942868429.issue26158@psf.upfronthosting.co.za>
In-reply-to
Content
io.IOBase.truncate() documentation says:
"Resize the stream to the given size in bytes (or the current position if size is not specified). The current stream position isn’t changed. This resizing can extend or reduce the current file size. In case of extension, the contents of the new file area depend on the platform (on most systems, additional bytes are zero-filled). The new file size is returned."

However:
>>> open('temp.txt', 'w').write('ABCDE\nFGHIJ\nKLMNO\nPQRST\nUVWXY\nZ\n')
32
>>> f = open('temp.txt', 'r+')
>>> f.readline()
'ABCDE\n'
>>> f.tell()
6                   # As expected, current position is 6 after the readline
>>> f.truncate()
32                  # ?!

Verified that the document does not get truncated to 6 bytes as expected. Adding an explicit f.seek(6) before the truncate causes it to work properly (truncate to 6). It also works as expected using a StringIO rather than a file, or in Python 2 (used 2.7.9).

Tested in 3.4.3/Windows, 3.4.1/Linux, 3.5.1/Linux.
History
Date User Action Args
2016-01-19 15:19:45fornaxsetrecipients: + fornax
2016-01-19 15:19:44fornaxsetmessageid: <1453216784.99.0.234942868429.issue26158@psf.upfronthosting.co.za>
2016-01-19 15:19:44fornaxlinkissue26158 messages
2016-01-19 15:19:44fornaxcreate