Input from the same file as the script

Dieter Maurer dieter at handshake.de
Tue Aug 22 13:19:44 EDT 2006


Georg Brandl <g.brandl-nospam at gmx.net> writes on Sun, 20 Aug 2006 20:08:38 +0200:
> poggle.themammal at gmail.com wrote:
> > 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 ?
> > When I ran the below the python interpreter gave an error.

The easiest way would be:

     data = '''\
     here comes your data
     ...
     '''

     # and now you use it
     ... data ...

     # you can even wrap it into a file
     from StringIO import StringIO
     data_as_file = StringIO(data)
     ... data_as_file.readline() ...

--
Dieter



More information about the Python-list mailing list