Python Tutorial Python Advanced Python References Python Libraries

Python - File fileno() Method



The Python fileno() method returns 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.

Return Value

Returns the file descriptor of the file stream as a number.

Example: Close an opened file in Python

In the example below, Python fileno() method returns the file descriptor of the file stream MyFile.

MyFile = open("test.txt", "w+")

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

The output of the above code will be:

3

❮ Python File Handling Methods