This article describes how to use the close () method to close a file in Python programming. It is a basic knowledge in Python programming. For more information, see close () method To close open files. The closed file cannot read or write more things. If the file is closed, any operation will cause a ValueError. However, you can call close () multiple times.
Python is automatically disabled when the referenced object of a file is reassigned to another file. It uses the close () method to close a file.
Syntax
The syntax of the close () method is as follows:
FileObject. close ();
Parameters
Return Value
This method does not return any value
Example
The following example shows how to use the close () method.
#! /Usr/bin/python # Open a filefo = open ("foo.txt", "wb") print "Name of the file:", fo. name # Close opend filefo. close ()
When we run the above program, it will produce the following results:
Name of the file: foo.txt