A few beginning questions
Mel Wilson
mwilson at the-wire.com
Mon Jul 14 12:52:47 EDT 2003
In article <xqx65m59pei.fsf at cola2.ca.boeing.com>,
Harry George <harry.g.george at boeing.com> wrote:
>"richardc" <richardc at hmgcc.gov.uk> writes:
>> Im looking for an agument parsing library (from the command line), Ive come
>> across optik and argtools. What other ones are there are any of them any
>> good, is there a 'standard' lib for doing this.
>1. args: I use getopt, which does the job. The idiom is:
>if __name__ == '__main__':
> opts,pargs=getopt.getopt(sys.argv[1:],'hvd',
> ['help','version','debug',
> 'bb='])
> for opt in opts:
> if opt[0]=='-h' or opt[0]=='--help':
> print modname+": version="+__version__
> usage()
> sys.exit(0)
> elif opt[0]=='-v' or opt[0]=='--version':
> print modname+": version="+__version__
> sys.exit(0)
> elif opt[0]=='-d' or opt[0]=='--debug':
> debug_p=1
> elif opt[0]=='--bb':
> opt_b=opt[1]
>
Although I really would recommend one change:
for opt, val in opts:
if opt in ('-h', '--help'):
print modname + ": version=" + __version__
usage()
sys.exit(0)
,,,
elif opt == '--bb':
opt_b = val
Regards. Mel.
More information about the Python-list
mailing list