.close()

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()

Contributors

Interested in helping build Docs? Read the Contribution Guide or share your thoughts in this feedback form.

Learn Python on Codecademy

Contributors