command line arguments?

george young gry at
Wed Aug 14 22:50:38 CEST 2002

On Wed, 14 Aug 2002 13:55:54 -0400
"Steve Holden" <sholden at> wrote:

> <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:

Also, don't forget about getopts,e.g.:

import getopts

    opts, args = getopt.getopt(sys.argv[1:], 'hz')
except getopt.error, errmsg:
    print >>sys.stderr, errmsg
    print >>sys.stderr, usage

ident ='This is %s version %s last edited by %s on %s' % (programname, cvs_rev, cvs_author, cvs_date)

for o,a in opts:
    if o == '-h':
        print __doc__
        print ident
        print usage
    elif o == '-z':
        debug = 1
        print usage

 I cannot think why the whole bed of the ocean is
 not one solid mass of oysters, so prolific they seem. Ah,
 I am wandering! Strange how the brain controls the brain!
	-- Sherlock Holmes in "The Dying Detective"

More information about the Python-list mailing list