Facebook Page Twitter Page LinkedIn Page
× Python Tutorial Python Advanced Python Resources Python Libraries


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.

Return Value

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

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)

The output of the above code will be:

3

❮ Python File Handling Methods