[Tutor] input and output files from terminal

Alan Gauld alan.gauld at btinternet.com
Thu Apr 17 18:40:23 CEST 2008


"Brain Stormer" <brnstrmrs at gmail.com> wrote

> Thanks for the file direction method but how do I get the names of 
> the files
> so I can use it inside my program.

I'm not sure I understand.

Thepoint of using redirection is that your code doesn't need to know
anything about the files, it just reads/writes to/from stdin/stdout.

The OS connects the bits together at runtime.

>> Easier to use file redirection:
>>
>> python test.py < inputfile > outputfile

So you can provide any name you like for inputfile
and outputfile when you execute the program.

If you want the program to read/write to a specific file then
use the standard open()/read/write functions

Or am I missing something?

Alan G. 




More information about the Tutor mailing list