Created
December 27, 2010 11:16
-
-
Save mvaz/756055 to your computer and use it in GitHub Desktop.
Python main() functions
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
# taken from http://www.artima.com/weblogs/viewpost.jsp?thread=4829 | |
import sys | |
import getopt | |
class Usage(Exception): | |
def __init__(self, msg): | |
self.msg = msg | |
def main(argv=None): | |
if argv is None: | |
argv = sys.argv | |
try: | |
try: | |
opts, args = getopt.getopt(argv[1:], "h", ["help"]) | |
except getopt.error, msg: | |
raise Usage(msg) | |
# more code, unchanged | |
except Usage, err: | |
print >>sys.stderr, err.msg | |
print >>sys.stderr, "for help use --help" | |
return 2 | |
if __name__ == "__main__": | |
sys.exit(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment