diff options
author | Volker-Weissmann <39418860+Volker-Weissmann@users.noreply.github.com> | 2020-11-27 00:41:32 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-27 00:41:32 (GMT) |
commit | c8aaf71dde4888864c0c351e2f935f87652c3d54 (patch) | |
tree | ec353c9340e305b540eb144975ab858c8b674f41 /Doc/tutorial/inputoutput.rst | |
parent | a1652da2c89bb21f3fdc71780b63b1de2dff11f0 (diff) | |
download | cpython-c8aaf71dde4888864c0c351e2f935f87652c3d54.zip cpython-c8aaf71dde4888864c0c351e2f935f87652c3d54.tar.gz cpython-c8aaf71dde4888864c0c351e2f935f87652c3d54.tar.bz2 |
bpo-17852: Doc: Fix the tutorial about closing files (GH-23135)
Co-authored-by: Inada Naoki <songofacandy@gmail.com>
Diffstat (limited to 'Doc/tutorial/inputoutput.rst')
-rw-r--r-- | Doc/tutorial/inputoutput.rst | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/Doc/tutorial/inputoutput.rst b/Doc/tutorial/inputoutput.rst index 366a532..4e27cff 100644 --- a/Doc/tutorial/inputoutput.rst +++ b/Doc/tutorial/inputoutput.rst @@ -329,11 +329,16 @@ equivalent :keyword:`try`\ -\ :keyword:`finally` blocks:: If you're not using the :keyword:`with` keyword, then you should call ``f.close()`` to close the file and immediately free up any system -resources used by it. If you don't explicitly close a file, Python's -garbage collector will eventually destroy the object and close the -open file for you, but the file may stay open for a while. Another -risk is that different Python implementations will do this clean-up at -different times. +resources used by it. + +.. warning:: + Calling ``f.write()`` without using the :keyword:`!with` keyword or calling + ``f.close()`` **might** result in the arguments + of ``f.write()`` not being completely written to the disk, even if the + program exits successfully. + +.. + See also https://bugs.python.org/issue17852 After a file object is closed, either by a :keyword:`with` statement or by calling ``f.close()``, attempts to use the file object will |