Join Nostr
2026-07-31 15:02:02 UTC

Cyrik on Nostr: #Python tip: If you're writing a script in the "traditional Unix" style, where it ...

#Python tip: If you're writing a script in the "traditional Unix" style, where it streams input from one or more sources and defaults to stdin, the fileinput module does all that for you. Just say:

for line in fileinput.input(): ...

And you'll get lines from all the files named in your command line arguments.

If your script does its own argument parsing, no problem, just pass the list of filenames from your argument parser to fileinput.input().

The module can report back filename and line number for logs and error messages. Check it out: https://docs.python.org/3/library/fileinput.html