The method close() closes the associated with file descriptor fd.
fd -- This is the file descriptor of the file.
#!/usr/bin/python import os, sys # Open a file fd = os.open( "foo.txt", os.O_RDWR|os.O_CREAT ) # Write one string os.write(fd, "This is test") # Close opened file os.close( fd ) print "Closed the file successfully!!"
When we run above program, it produces following result:
Closed the file successfully!!