command line arguments?

Steve Holden sholden at
Wed Aug 14 13:55:54 EDT 2002

<brobbins333 at> 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 arg1 arg2

Yes, using sys.argv. Supposing "" reads:

import sys
for arg in sys.argv:
    print "Arg", arg

then your run would look as follows:

C:\> python arg1 arg2
Arg arg1
Arg arg2

Element zero gets the script name, successive elements get the arguments
they correspond to.


More information about the Python-list mailing list