script that parses command line, and execfile('')

Tim Chase python.list at tim.thechases.com
Tue Nov 4 06:12:59 EST 2008


Sandip Bhattacharya wrote:
> On Nov 4, 12:43 am, "Diez B. Roggisch" <de... at nospam.web.de> wrote:
>> def main(argv=None):
>>      if argv is None: argv = sys.argv[1:]
>>      ...
> 
> Wouldn't that make optparse miss the first parameter sys.argv[1]
> mistaking it to be the name of the current program?

Nope...optparse uses argv[1:] as documented at [1].  The "prog" 
argument can be specified in the constructor to OptionParser, but 
defaults to sys.argv[0] if it's not been explicitly specified.[2]

-tkc


[1]
http://www.python.org/doc/2.5.2/lib/optparse-parsing-arguments.html

[2]
http://www.python.org/doc/2.5.2/lib/optparse-creating-parser.html
(at the "prog" entry at the bottom)



More information about the Python-list mailing list