On this page
fileinput.filename
Prev: fileinput.filelineno | Up: fileinput | Next: fileinput.fileno
Rel: fileinput.close, fileinput.FileInput, fileinput.filelineno, fileinput.fileno
Ref: docs.python.org — fileinput.filename
Tags: #public #python3 #stdlib #fileinput
Import
import fileinput
from fileinput import filename
Signature & Overview
fileinput.filename()
Return the name of the file currently being read.
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 Path(f.filename()).name == "a.txt"
Gotchas
- Returns
Nonebefore the first line is read.
REPL Inspect
from fileinput import filename
help(filename)
Linked from
- tuts/python3/stdlib_module/fileinput
- tuts/python3/stdlib_module/fileinput/close
- tuts/python3/stdlib_module/fileinput/FileInput
- tuts/python3/stdlib_module/fileinput/filelineno
- tuts/python3/stdlib_module/fileinput/fileno
- tuts/python3/stdlib_module/fileinput/hook_compressed
- tuts/python3/stdlib_module/fileinput/hook_encoded
- tuts/python3/stdlib_module/fileinput/input
- tuts/python3/stdlib_module/fileinput/isfirstline
- tuts/python3/stdlib_module/fileinput/isstdin
- tuts/python3/stdlib_module/fileinput/lineno
- tuts/python3/stdlib_module/fileinput/nextfile
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/fileno Linked here; links to this page; shared tags: #fileinput, #stdlib
- tuts/python3/stdlib_module/fileinput/hook_compressed links to this page; shared tags: #fileinput, #stdlib
- tuts/python3/stdlib_module/fileinput/hook_encoded links to this page; shared tags: #fileinput, #stdlib
- tuts/python3/stdlib_module/fileinput/input links to this page; shared tags: #fileinput, #stdlib
- tuts/python3/stdlib_module/fileinput/isfirstline links to this page; shared tags: #fileinput, #stdlib
- tuts/python3/stdlib_module/fileinput/isstdin links to this page; shared tags: #fileinput, #stdlib
- tuts/python3/stdlib_module/fileinput/lineno links to this page; shared tags: #fileinput, #stdlib