os.closerange() Overview
The os.closerange() method is used to close all file descriptors fd, from fd_low (included) to fd_high (not included), errors are ignored.
os.closerange() Syntax
The closerange() method syntax format is as follows:
os.closerange(fd_low, fd_high);
os.closerange() Parameter
- fd_low – minimum file descriptor
- fd_high – maximum file descriptor
The method is similar to:
for fd in xrange(fd_low, fd_high):
try:
os.close(fd)
except OSError:
pass
os.closerange() Return Value
This method has no return value.
os.closerange() Demo
The following example demonstrates the use of the closerange() method:
#!/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 the file
os.closerange( fd, fd)
print ("Close file successfully!!!")
The output of executing the above program is:
Close file successfully!!!