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