New submission from otn <[email protected]>:
For opened file as "r+", even if write() then readline(), readline() is
executed first.
When add tell() after write(), it works correctly.
==========================================
data1 = "aa\nbb\ncc\n"
data2 = "xx\n"
with open("data.txt","w") as f:
f.write(data1)
with open("data.txt","r+") as f:
f.write(data2)
# f.tell()
print("Line:",repr(f.readline()))
with open("data.txt") as f:
print("All:",repr(f.read()))
==========================================
OUTPUT:
Line: 'aa\n'
All: 'aa\nbb\ncc\nxx\n'
EXPECTED:
Line: 'bb\n'
All: 'xx\nbb\ncc\n'
----------
components: IO
messages: 400826
nosy: otn
priority: normal
severity: normal
status: open
title: open "r+" problem
type: behavior
versions: Python 3.9
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue45076>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com