.close()

christian.dinh2481 total contributions
Published May 10, 2021Updated Aug 6, 2023
Contribute to Docs
The .close()
file method allows the user to close an open file within the IDE.
Syntax
file.close()
Example
Use .close()
to close the opened gullivers_travels.txt
file:
f = open("gullivers_travels.txt", "r", encoding='utf8')f.close()
Codebyte Example
The example below opens a file called example_file.txt
and then closes it using .close()
. The .closed
attribute is used to show whether the file is open or closed.
All contributors
- christian.dinh2481 total contributions
- Anonymous contributorAnonymous contributor3077 total contributions
- Anonymous contributorAnonymous contributor194 total contributions
- net137228473814 total contributions
- Anonymous contributorAnonymous contributor15 total contributions
- christian.dinh
- Anonymous contributor
- Anonymous contributor
- net1372284738
- Anonymous contributor
Looking to contribute?
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.