Python method close() closes the associated with file descriptor fd.
Following is the syntax for close() method:
os.close(fd);
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!!"
When we run the above program, it produces the following result:
Closed the file successfully!!
Here at Intellinuts, we have created a complete Python tutorial for Beginners to get started in Python.