[Tutor] input and output files from terminal

Alan Gauld alan.gauld at btinternet.com
Mon Apr 14 20:57:22 CEST 2008


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

>I have a python program which works fine when run using idle but I 
>would
> like call the program from the terminal.
>
> python test.py -i inputfile -o outputfile

Easier to use file redirection:

python test.py < inputfile > outputfile

The -i flag in particular might conflict with Pythons own -i option.

> I tried with raw_input but that only works in idle.

What makes you think that?
raw_input is the normal way to get input from stdin.

Can you explain what you did and what the result was?
Perhaps with a short code example?

Try this for example:

####################

name = raw_input('What's your name? ')
print "hello", name

####################

That can be run in IDLE or in a command window
or using file redirection as described above.

Tell us how you get on...


-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld




More information about the Tutor mailing list