Python - File fileno() Method


Advertisements

The Python file fileno() method is used to return the file descriptor of the file stream as a number. The method raises an exception if the operating system does not use a file descriptor.

Syntax


file.fileno()

Parameters

No parameter is required.

Example: Close an opened file in Python

In the below example, Python fileno() method is used to return the file descriptor of the file stream of file called MyFile.

MyFile = open("python_test.txt", "r")

#file descriptor of the file stream
x = MyFile.fileno()
print(x)

Output

3

Python File Handling Methods
Advertisements