.close()

Anonymous contributors
Anonymous contributors
Published May 10, 2021Updated Apr 12, 2022
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()

All contributors

Looking to contribute?

Learn Python on Codecademy