You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
The return of truncate(size=None) (file io) is unexpected #79485
This is the same as bpo-26158. Truncating text files is not clearly documented for a start, and truncating after reading doesn’t seem to be considered much in the implementations.
Your question is answered at <https://bugs.python.org/issue26158#msg258619\>. Your code calls the C implementation of “io.TextIOWrapper.truncate”. This implementation does not consider that there are 8 unread bytes in a buffer, so it truncates the file at the end of the buffer (5 read + 8 unread = 13 bytes).
Activity
liugang93 commentedon Nov 23, 2018
-- run in Windows 10
1 -
f = open('test', "w+")
f.write('xxx\nyyy\nzzz')
2 -
f = open('test', "w+")
f.write('xxx\nyyy\nzzz')
liugang93 commentedon Nov 23, 2018
# Run in Windows 10
vadmium commentedon Nov 24, 2018
This is the same as bpo-26158. Truncating text files is not clearly documented for a start, and truncating after reading doesn’t seem to be considered much in the implementations.
Your question is answered at <https://bugs.python.org/issue26158#msg258619\>. Your code calls the C implementation of “io.TextIOWrapper.truncate”. This implementation does not consider that there are 8 unread bytes in a buffer, so it truncates the file at the end of the buffer (5 read + 8 unread = 13 bytes).