Python os.close() Method
The method close() closes the associated with file descriptor fd.
Following is the syntax for close() method
fd -- This is the file descriptor of the file.
This method does not return any value.
The following example shows the usage of close() method.
#!/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!!"
Let us compile and run the above program, this will produce the following result:
Closed the file successfully!!