On this page
fileinput.fileno
Prev: fileinput.filename | Up: fileinput | Next: fileinput.hook_compressed
Rel: fileinput.close, fileinput.FileInput, fileinput.filelineno, fileinput.filename
Ref: docs.python.org — fileinput.fileno
Tags: #public #python3 #stdlib #fileinput
Import
import fileinput
from fileinput import fileno
Signature & Overview
fileinput.fileno()
Return the file number of the current file. When no file is currently opened, returns -1.
Usage
import fileinput
from pathlib import Path
import tempfile
with tempfile.TemporaryDirectory() as tmp:
p = Path(tmp) / "a.txt"
p.write_text("hi\n", encoding="utf-8")
with fileinput.input(files=(p,), encoding="utf-8") as f:
next(f)
assert f.fileno() >= 0
Gotchas
- Returns
-1when no file is currently open.
REPL Inspect
from fileinput import fileno
help(fileno)
Linked from
Related notes
- tuts/python3/stdlib_module/fileinput/close Linked here; links to this page; shared tags: #fileinput, #stdlib
- tuts/python3/stdlib_module/fileinput/FileInput Linked here; links to this page; shared tags: #fileinput, #stdlib
- tuts/python3/stdlib_module/fileinput/filelineno Linked here; links to this page; shared tags: #fileinput, #stdlib
- tuts/python3/stdlib_module/fileinput/filename Linked here; links to this page; shared tags: #fileinput, #stdlib
- tuts/python3/stdlib_module/fileinput/hook_compressed Linked here; links to this page; shared tags: #fileinput, #stdlib
- tuts/python3/stdlib_module/fileinput links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/fileinput/hook_encoded shared tags: #fileinput, #stdlib
- tuts/python3/stdlib_module/fileinput/input shared tags: #fileinput, #stdlib
- tuts/python3/stdlib_module/fileinput/isfirstline shared tags: #fileinput, #stdlib
- tuts/python3/stdlib_module/fileinput/isstdin shared tags: #fileinput, #stdlib