Last active
August 29, 2015 14:07
-
-
Save edunham/3b00f2cced7782a58838 to your computer and use it in GitHub Desktop.
A hello world that uses getopt
This file contains hidden or 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
#!/usr/bin/env python | |
import getopt | |
import sys | |
try: | |
opts, args = getopt.getopt(sys.argv[1:], "g:s:", ["given=", "surname="]) | |
except getopt.GetoptError as err: | |
print str(err) # will print something like "option -a not recognized" | |
sys.exit(2) | |
given = surname = None | |
for opt, arg in opts: | |
if opt in ('-g', '--given'): | |
given = arg | |
elif opt in ('-s', '--surname'): | |
surname = arg | |
if given is None or surname is None: | |
print "please supply both given name and surname" | |
sys.exit(2) | |
print "hello, " + given + ' ' + surname |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment