A few beginning questions
Harry George
harry.g.george at boeing.com
Mon Jul 14 10:03:17 EDT 2003
"richardc" <richardc at hmgcc.gov.uk> writes:
> Ive just started playing with Python and have a couple of questions.
>
> 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.
>
> Also how should I '#define' magic numbers in Python. I spent ages looking
> around for a 'define' statement or anything that will allow me to create a
> constant value 'object'. Am I missing something very obvious ?
>
> Also, what 'IDE/editor' do people recomend for MAC OSX, so far Ive found
> 'Hydra' to be the best as it works on plain files and has Python syntax
> highlighting... what else is there and are any of them any good.
>
> Has nobody written an editor/IDE in Python with wxWindows so that it runs on
> all platforms ?
>
> Many thanks
>
> Rich
>
>
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]
2. #define: Use ALLCAPS. I put these all in a globals section at the
top of the module in the order: docstring, imports, globals,
utilities, common functions, classes, "main", and "if
__name__=='__main__':"
Also, if you have global variables, we use leading "g_"
(e.g,"g_myglobaldata"), so they are easy to find if encountered in
the body of the module.
--
harry.g.george at boeing.com
6-6M31 Knowledge Management
Phone: (425) 294-8757
More information about the Python-list
mailing list