Tutorials Point


  Python Basics
  Python Advanced
  Python Useful References
  Python Useful Resources
  Selected Reading

© 2011 TutorialsPoint.COM


  Home     References     Discussion Forums     About TP  

Python File close() Method


previous next AddThis Social Bookmark Button


Description:

This method closes the opend file. A closed file cannot be read or written any more. Any operation which requires that the file be open will raise a ValueError after the file has been closed. Calling close() more than once is allowed.

Python automatically closes a file when the reference object of a file is reassigned to another file. It is a good practice to use the close() method to close a file.

Syntax:

fileObject.close(); 

Parameters:

Here is the detail of parameters:

  • NA

Example:

#!/usr/bin/python

# Open a file
fo = open("foo.txt", "wb")
print "Name of the file: ", fo.name

# Close opend file
fo.close()

This produces following result:

Name of the file:  foo.txt


previous next Printer Friendly



  

Advertisement

Online Image Processing

Indian Baby Names