os.close Overview
The os.close() method is used to close the specified file descriptor fd.
os.close Syntax
The close() method syntax format is as follows:
os.close(fd);
os.close Parameter
- fd – file descriptor.
os.close Return Value
This method has no return value.
os.close Demo
The following example demonstrates the use of the close() method:
#!/usr/bin/python3
import os, sys
# Open file
fd = os.open( "foo.txt", os.O_RDWR|os.O_CREAT )
# Write to string
os.write(fd, "This is test")
# Close the file
os.close( fd )
print ("Close file successfully!!!")
The output of the above program is:
Close file successfully!!!