open(..., 'w') ... flush() fails to write data to the file
See original GitHub issueRepro:
with open('test.txt', 'w') as test:
test.write('hi')
test.flush()
r = open('test.txt', 'r')
print(r.read(1))
r.close()
Expected: ‘h’ printed Actual: ‘’ printed
This seems to be a regression from IronPython 2.
Side note: what surprises me is that in both 3 and 2 BufferedWriter.flush()
does not call .flush()
on the underlying _raw
/_rawIO
, but somehow it works in IronPython 2. I’d appreciate an explanation. Does IP2 create the underlying stream with buffering off?
Issue Analytics
- State:
- Created 5 years ago
- Comments:10 (6 by maintainers)
Top Results From Across the Web
How often does python flush to a file? - Stack Overflow
From the docs: Note: flush() does not necessarily write the file's data to disk. Use flush() followed by os.fsync() to ensure this behavior....
Read more >Python File flush() Method - Tutorialspoint
Description. Python file method flush() flushes the internal buffer, like stdio's fflush. This may be a no-op on some file-like objects.
Read more >File flush() method in Python - GeeksforGeeks
The flush() method in Python file handling clears the internal buffer of the file. In Python, files are automatically flushed while closing ...
Read more >File Reading and Writing Methods - Python 2.7 Tutorial
Create a file object using the open() function. Along with the file name, specify: 'r' for reading in an existing file (default; can...
Read more >flush() [File]
Writes to disk a file previously opened with create( ) or open( ) without closing the file. Returns true if successful and false...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
My example is a counter-example to the statement that
BufferedWriter
should call the underlying IO object’sflush
. If it did callflush
, then the sample above would fail. You can manually flush theraw
and see the difference:@slozier I am not sure what do you mean here.
BufferedWriter
should be calling the underlying IO object’sflush
, so ifflush
is fixed to behave correctly, this would pass.