Python3 Os Closerange
# Python3.x Python3 os.closerange() Method
[ Python3 OS File/Directory Methods](#)
* * *
### Overview
The os.closerange() method is used to close all file descriptors from fd_low (inclusive) to fd_high (exclusive), ignoring errors.
### Syntax
The syntax for the **closerange()** method is as follows:
os.closerange(fd_low, fd_high);
### Parameters
* **fd_low** -- The lowest file descriptor.
* **fd_high** -- The highest file descriptor.
This method is similar to:
for fd in xrange(fd_low, fd_high): try: os.close(fd) except OSError: pass
### Return Value
This method does not return a value.
### Example
The following example demonstrates the use of the closerange() method:
#!/usr/bin/python3import os, sys # Open a file fd = os.open( "foo.txt", os.O_RDWR|os.O_CREAT )# Write a string os.write(fd, "This is test")# Close the file os.closerange( fd, fd)print ("File closed successfully!!")
Executing the above program outputs the following result:
File closed successfully!!
[ Python3 OS File/Directory Methods](#)
YouTip