fileno()方法返回所使用的底層實現(xiàn),要求從操作系統(tǒng)I/O操作的整數(shù)文件描述符。
語法
以下是fileno()方法的語法:
1
|
fileObject.fileno(); |
參數(shù)
- NA
返回值
此方法返回整數(shù)文件描述符。
例子
下面的例子顯示fileno()方法的使用。
1
2
3
4
5
6
7
8
9
10
11
|
#!/usr/bin/python # 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() |
當(dāng)我們運行上面的程序,它會產(chǎn)生以下結(jié)果:
1
2
|
Name of the file : foo.txt File Descriptor: 3 |