Input from a file as a command line argument
Thomas Heller
theller at python.net
Sat Apr 5 11:38:51 EST 2003
Teemu Luojola <teemu.luojola at pbezone.net> writes:
> I have read through Python documentation and tried several searches,
> but I can't find a simple answer to this question.
>
>
> If I make an executable script in linux environment, how can I pass
> input to that script from a file on command line? Like the following:
>
>
> $ script.py input.txt
>
> or perhaps
>
> $ script.py < input.txt
>
See module fileinput.
import fileinput
for line in fileinput.input():
process(line)
Thomas
More information about the Python-list
mailing list