[Tutor] Command Line Arguements in Python
Tue, 16 Oct 2001 20:38:44 -0700 (PDT)
On Tue, 16 Oct 2001, Mike Yuen wrote:
> I'm having some trouble reading input and writing output files from the
> command line as follows:
> python myfile.py < inputfile.txt > outputfile.txt
> The problem is, I don't know how to get access to the inputfile.txt
> and outputfile.txt inside my code. Normally, i'm used to using the
> "open" command but I don't want to hard code it in anymore. FYI, i'm
> using Python on a UNIX O/S.
Ah, you'll like this one. Take a look at 'sys.stdin' and 'sys.stdout':
What you know already about file handles can apply directly to reading and
writing to "standard input" and "standard output". The only difference is
that these 'files' are already open().
Hope this helps!