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.htmlPublished at
2026-07-31 15:02:02 UTCEvent JSON
{
"id": "18843ecb8b9f3beccfc3719c6a4abf7c08f3237066408e5be8039c74a6e51a70",
"pubkey": "be144ae9d50ca9dea6a9ab6eefce99740ad3e2a69ab5891ae29d766965db8a60",
"created_at": 1785510122,
"kind": 1,
"tags": [
[
"proxy",
"https://dragonchat.org/@CyrikCroc/117015191409727558",
"web"
],
[
"t",
"python"
],
[
"proxy",
"https://dragonchat.org/ap/users/116403862319522649/statuses/117015191409727558",
"activitypub"
],
[
"L",
"pink.momostr"
],
[
"l",
"pink.momostr.activitypub:https://dragonchat.org/ap/users/116403862319522649/statuses/117015191409727558",
"pink.momostr"
],
[
"-"
]
],
"content": "#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:\n\nfor line in fileinput.input(): ...\n\nAnd you'll get lines from all the files named in your command line arguments.\n\nIf your script does its own argument parsing, no problem, just pass the list of filenames from your argument parser to fileinput.input().\n\nThe module can report back filename and line number for logs and error messages. Check it out: https://docs.python.org/3/library/fileinput.html",
"sig": "c94ee646b995697db8b1bddf3dbf7e95ed798381859bfce1eb49b4460c42c2cd8130dc39b6c295019f65cfa2e49968d03d75dc4edc5a76f66c04b07ea5789ace"
}