Message292866
The doc says that StringIO.truncate should not change the current position.
Consider this code:
try:
import StringIO
except ImportError:
import io as StringIO
buf = StringIO.StringIO()
assert_equal(buf.getvalue(), "")
print("buf: %r" % buf.getvalue())
buf.write("hello")
print("buf: %r" % buf.getvalue())
assert_equal(buf.getvalue(), "hello")
buf.truncate(0)
print("buf: %r" % buf.getvalue())
assert_equal(buf.getvalue(), "")
buf.write("hello")
print("buf: %r" % buf.getvalue())
assert_equal(buf.getvalue(), "\x00\x00\x00\x00\x00hello")
buf.truncate(0)
print("buf: %r" % buf.getvalue())
assert_equal(buf.getvalue(), "")
On Python 3.6, I get the output:
buf: ''
buf: 'hello'
buf: ''
buf: '\x00\x00\x00\x00\x00hello'
On Python 2.7, I get the output:
buf: ''
buf: 'hello'
buf: ''
buf: 'hello'
Thus it seems that Python 2.7 StringIO.truncate does actually resets the position for this case or there is some other bug in Python 2.7. At least from the doc, it seems that the Python 3.6 behavior is the expected behavior. |
|
Date |
User |
Action |
Args |
2017-05-03 09:21:27 | Albert.Zeyer | set | recipients:
+ Albert.Zeyer |
2017-05-03 09:21:26 | Albert.Zeyer | set | messageid: <1493803286.93.0.729183089652.issue30250@psf.upfronthosting.co.za> |
2017-05-03 09:21:26 | Albert.Zeyer | link | issue30250 messages |
2017-05-03 09:21:26 | Albert.Zeyer | create | |
|