Python Tutorial Python Advanced Python Resources Python Libraries
Python Java C++ C C# PHP R SQL DS Algo InterviewQ

Python - File fileno() Method



The Python file 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

5