[Tutor] passing variable to python script

bob bgailer at alum.rpi.edu
Fri Oct 14 01:28:50 CEST 2005

At 04:09 PM 10/13/2005, Marc Buehler wrote:
>i want to pass an argument (a number) to a python
>script when running it:
> > python script.py <number>
>i want to be able to use <number> within script.py
>as a parameter.
>how do i set this up?

In the sys module there is a property argv. The docs say: "The list of 
command line arguments passed to a Python script. argv[0] is the script name"

import sys
if len(argv) < 2:
   print "Usage: script.py <number>"
   numeric_arg = int(argv[1])
   print '1st argument must be numeric."

More information about the Tutor mailing list