Python3 os.closerange() Method
Python3 OS File/Directory Methods
Overview
The os.closerange() method is used to close all file descriptors fd from fd_low (inclusive) to fd_high (exclusive), ignoring errors.
Syntax
closerange()The method syntax is as follows:
os.closerange(fd_low, fd_high);
Parameters
fd_low-- minimum file descriptor
fd_high-- maximum 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 has no return value.
Examples
The following example demonstrates the use of the closerange() method:
#!/usr/bin/python3
import os, sys
# 打开文件
fd = os.open( "foo.txt", os.O_RDWR|os.O_CREAT )
# 写入字符串
os.write(fd, "This is test")
# 关闭文件
os.closerange( fd, fd)
print ("关闭文件成功!!")
The output of executing the above program is:
File closed successfully!!Other Extensions