Python文件fileno()
方法用于返回底层实现使用的整数文件描述符,以从操作系统请求I/O
操作。
语法
以下是fileno()
方法的语法 -
fileObject.fileno()
参数
- NA
返回值
- 此方法不返回任何值。
示例
以下示例显示了fileno()
方法的用法。
#!/usr/bin/python3
# Open a file
fo = open("foo.txt", "wb")
print ("Name of the file: ", fo.name)
fid = fo.fileno()
print ("File Descriptor: ", fid)
# Close opend file
fo.close()
执行上面代码后,将得到以下结果 -
Name of the file: foo.txt
File Descriptor: 3