Python 3 – File fileno() Method

Python 3 – File fileno() Method

Description

The fileno() method returns an integer file descriptor, which is used to request I/O operations.

Syntax

The following is the syntax of the fileno() method −

fileObject.fileno()

Parameters

NA

Return Value

This method returns an integer file descriptor.

Example

The following example demonstrates the usage of the fileno() method.

#!/usr/bin/python3

# Open a file
fo = open("foo.txt", "wb")
print ("File name: ", fo.name)

fid = fo.fileno()
print ("File descriptor: ", fid)

# Close a file
fo.close()

Result

When running the above program, it produces the following output −

File name: foo.txt
File descriptor: 3

Leave a Reply

Your email address will not be published. Required fields are marked *