File Methods
fileno()
Return the integer file descriptor used by the underlying operating system.
file.fileno()
file.fileno() returns the integer file descriptor assigned to the open file by the OS.
Result
Returns
An integer representing the operating system file descriptor.
Run it
Try it
Run it and change it
import tempfile
with tempfile.NamedTemporaryFile(mode='w+', delete=True) as f:
fd = f.fileno()
print('Is integer FD:', isinstance(fd, int)) Output
Press Run to see what it prints.Worth knowing
- Low-level OS operations: File descriptors are used with the
osmodule functions likeos.read(),os.write(), andos.fstat().