Wednesday, March 18, 2015

Gudio Van Rossum Main()

I've written a few main() functions in my time. They usually have a structure roughly like this:


"""Module docstring.

This serves as a long usage message.
"""
import sys
import getopt

def main(): # parse command line options try: opts, args = getopt.getopt(sys.argv[1:], "h", ["help"]) except getopt.error, msg: print msg print "for help use --help" sys.exit(2) # process options for o, a in opts: if o in ("-h", "--help"): print __doc__ sys.exit(0) # process arguments for arg in args: process(arg) # process() is defined elsewhere if __name__ == "__main__": main()


By:

Guido Van Rossum 

No comments:

Post a Comment