YouTip LogoYouTip

File Close

# Python2.x Python File close() Method [![Image 3: Python File Methods](#) Python File Methods](#) * * * ### Overview The **close()** method is used to close an opened file. A closed file can no longer be read from or written to, otherwise a _ValueError_ error will be triggered. The close() method can be called multiple times. When a file object is referenced to operate on another file, Python will automatically close the previous file object. Using the close() method to close files is a good habit. ### Syntax The syntax of the close() method is as follows: fileObject.close(); ### Parameters * **None** ### Return Value This method does not have a return value. ### Example The following example demonstrates the use of the close() method: #!/usr/bin/python# -*- coding: UTF-8 -*-# Open file fo = open(".txt", "wb")
← Linux Comm RpmLinux Comm Grpconv β†’