[New-bugs-announce] [issue45076] open "r+" problem
otn
report at bugs.python.org
Wed Sep 1 07:56:20 EDT 2021
New submission from otn <ootani.takashi at gmail.com>:
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 <report at bugs.python.org>
<https://bugs.python.org/issue45076>
_______________________________________
More information about the New-bugs-announce
mailing list