Message258600
| 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:45 | fornax | set | recipients:
+ fornax |
| 2016年01月19日 15:19:44 | fornax | set | messageid: <1453216784.99.0.234942868429.issue26158@psf.upfronthosting.co.za> |
| 2016年01月19日 15:19:44 | fornax | link | issue26158 messages |
| 2016年01月19日 15:19:44 | fornax | create |
|