Input from the same file as the script

Hendrik van Rooyen mail at microcorp.co.za
Mon Aug 21 02:32:29 EDT 2006


 "Dennis Lee Bieber" <wlfraed at ix.netcom.com> Wrote:


| On 20 Aug 2006 11:02:25 -0700, poggle.themammal at gmail.com declaimed the
| following in comp.lang.python:
|
| > Can the input to the python script be given from the same file as the
| > script itself. e.g., when we execute a python script with the command
| > 'python <scriptName', can the input be given in someway ?
| >
| Redirecting? Ugh...
|
| Off-hand, I'd say NO
|
| There is no way to tell the python interpreter where the program
| ends and the "run data" begins.

You *could* jump through a hoop like this one:

ListOfInput = ['first input', 'second input', .......'last input']

and then read the elements of the list one by one...

You will probably have to make the list global to get it to work...

But I kind of agree with Dennis - I would not do it that way either - reading
the inputs from the stdin console is easy enough, or if there are just a few of
them, getting them as command line arguments is arguably even easier - and if
its a whole bunch of stuff that is painstaking to type in every time - put it in
a text file and read it line by line.

- Hendrik

-




More information about the Python-list mailing list