bpo-17852: Doc: Fix the tutorial about closing files (GH-23135)
Co-authored-by: Inada Naoki <songofacandy@gmail.com>
(cherry picked from commit c8aaf71dde
)
Co-authored-by: Volker-Weissmann <39418860+Volker-Weissmann@users.noreply.github.com>
This commit is contained in:
parent
bda2e68c88
commit
01fcde89d7
|
@ -329,11 +329,16 @@ equivalent :keyword:`try`\ -\ :keyword:`finally` blocks::
|
||||||
|
|
||||||
If you're not using the :keyword:`with` keyword, then you should call
|
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
|
``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
|
resources used by it.
|
||||||
garbage collector will eventually destroy the object and close the
|
|
||||||
open file for you, but the file may stay open for a while. Another
|
.. warning::
|
||||||
risk is that different Python implementations will do this clean-up at
|
Calling ``f.write()`` without using the :keyword:`!with` keyword or calling
|
||||||
different times.
|
``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
|
After a file object is closed, either by a :keyword:`with` statement
|
||||||
or by calling ``f.close()``, attempts to use the file object will
|
or by calling ``f.close()``, attempts to use the file object will
|
||||||
|
|
Loading…
Reference in New Issue