Created
May 25, 2013 09:26
-
-
Save nikoheikkila/5648502 to your computer and use it in GitHub Desktop.
Python: general main() function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Module docstring | |
This is a placeholder for a long usage message. | |
""" | |
import sys | |
import getopt | |
def process(arg): | |
""" Write a method for argument processing here """ | |
pass | |
def main(argv=None): | |
""" Main function """ | |
if argv is None: | |
argv = sys.argv | |
# Parse commandline options | |
try: | |
opts, args = getopt.getopt(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) | |
if __name__ == "__main__": | |
sys.exit(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment