On this page
fileinput.isstdin
Prev: fileinput.isfirstline | Up: fileinput | Next: fileinput.lineno
Rel: fileinput.close, fileinput.FileInput, fileinput.filelineno, fileinput.filename
Ref: docs.python.org — fileinput.isstdin
Tags: #public #python3 #stdlib #fileinput
Import
import fileinput
from fileinput import isstdin
Signature & Overview
fileinput.isstdin()
Returns true if the last line was read from sys.stdin, otherwise returns false.
Usage
import fileinput
from pathlib import Path
import tempfile
with tempfile.TemporaryDirectory() as tmp:
p = Path(tmp) / "a.txt"
p.write_text("x\n", encoding="utf-8")
with fileinput.input(files=(p,), encoding="utf-8") as f:
next(f)
assert f.isstdin() is False
Gotchas
- True when the current line came from
sys.stdin("-").
REPL Inspect
from fileinput import isstdin
help(isstdin)
Linked from
Related notes
- tuts/python3/stdlib_module/fileinput/isfirstline Linked here; links to this page; shared tags: #fileinput, #stdlib
- tuts/python3/stdlib_module/fileinput/lineno Linked here; links to this page; shared tags: #fileinput, #stdlib
- tuts/python3/stdlib_module/fileinput/close Linked here; shared tags: #fileinput, #stdlib
- tuts/python3/stdlib_module/fileinput/FileInput Linked here; shared tags: #fileinput, #stdlib
- tuts/python3/stdlib_module/fileinput/filelineno Linked here; shared tags: #fileinput, #stdlib
- tuts/python3/stdlib_module/fileinput/filename Linked here; shared tags: #fileinput, #stdlib
- tuts/python3/stdlib_module/fileinput links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/fileinput/fileno shared tags: #fileinput, #stdlib
- tuts/python3/stdlib_module/fileinput/hook_compressed shared tags: #fileinput, #stdlib
- tuts/python3/stdlib_module/fileinput/hook_encoded shared tags: #fileinput, #stdlib