i

Python Programming

Python File Close() Method

Close() method of file object flushes any unwritten information and closes file object, after which no more writing done.

Python automatically closes file when the reference object of file is re-assigned to other file. It is a good way to use close() method to close a file.

Syntax             >>>                 fileObject.close()

Example

Live Demo

Output:

Name of file:  foo.txt