Python File close() Method

❮ File Methods


Example

Close a file after it has been opened:

f = open("demofile.txt", "r")
print(f.read())
f.close()
Run Example »

Definition and Usage

The close() method closes an open file.

You should always close your files, in some cases, due to buffering, changes made to a file may not show until you close the file.


Syntax

file.close()

Parameter Values

No parameters


❮ File Methods

Copyright 1999-2023 by Refsnes Data. All Rights Reserved.