Input from a file as a command line argument
Teemu Luojola
teemu.luojola at pbezone.net
Sat Apr 5 08:36:26 EST 2003
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
I make now a comparison to a Perl script. In Perl I would write the
following to handle the input (line by line) from a file:
while (<>) {
## (do something to $_)
}
and I can execute the script simply with
$ script.perl < input.txt
and it would process each line in input.txt.
How would a similar Python code look like?
Teemu Luojola
More information about the Python-list
mailing list