[Tutor] passing variable to python script

John Fouhy john at fouhy.net
Fri Oct 14 01:19:09 CEST 2005


On 14/10/05, Marc Buehler <marc_buehler at yahoo.com> wrote:
> hi.
>
> i want to pass an argument (a number) to a python
> script when running it:
> > python script.py <number>

Have a look at sys.argv!

#### testargs.py ####
import sys
print sys.argv
####

C:\temp>python testargv.py 1 2 foo
['testargv.py', '1', '2', 'foo']

If you want to do anything vaguely complicated, have a look at the
getopt and optparse modules.

--
John.


More information about the Tutor mailing list