[issue45076] open "r+" problem

2021-09-01 Thread otn


otn  added the comment:

It works correct for ver2.6, and also "rb+".
Buffering procsess should work the same as those case.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45076] open "r+" problem

2021-09-01 Thread Zachary Ware


Zachary Ware  added the comment:

Usage questions like this are better suited to the Users category at 
https://discuss.python.org/c/users/7 or the python-l...@python.org mailing list.

The write is buffered.  If you want it to be written before you read, add 
`f.flush()` after the write; `f.tell()` causes an implicit flush.  See also the 
`buffering` argument to `open`.

--
nosy: +zach.ware
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45076] open "r+" problem

2021-09-01 Thread otn


New submission from otn :

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 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com