Closing a File

After performing operations on a file, the file should be closed again. The close() method is used for this purpose.

The syntax for closing a file is as follows:

Syntax

obj_name.close()

Example

fobj = open("myFile.txt", "w+")

# do something with fobj

fobj.close()