command line arguments?
Steve Holden
sholden at holdenweb.com
Wed Aug 14 13:55:54 EDT 2002
<brobbins333 at shaw.ca> wrote in message news:3d5a977e.9834056 at news...
> Is it possible to invoke a Python script with command line arguments
> in the manner of C?
>
>
> Something like this (not in the interactive interpreter):
>
> C:\> python myscript.py arg1 arg2
Yes, using sys.argv. Supposing "myscript.py" reads:
#
# myscript.py
#
import sys
for arg in sys.argv:
print "Arg", arg
then your run would look as follows:
C:\> python myscript.py arg1 arg2
Arg myscript.py
Arg arg1
Arg arg2
Element zero gets the script name, successive elements get the arguments
they correspond to.
regards
Steve
More information about the Python-list
mailing list