Created
October 1, 2014 02:46
-
-
Save itorres/82b9c43574f91636bb42 to your computer and use it in GitHub Desktop.
YAPOP (Yet Another Python Option Parser)
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
def getopt(wat,default=None): | |
""" | |
getopt("flag") returns a bool | |
getopt("flag","default value") returns the next item in the argument list | |
Examples: | |
when calling "script -f filename": | |
getopt("-f","defaultname") would return "filename" | |
getopt("-v") would return False | |
when calling "script -v": | |
getopt("-f","defaultname") would return "defaultname" | |
getopt("-v") would return True | |
""" | |
if wat in sys.argv: | |
index = sys.argv.index(wat) | |
del sys.argv[index] | |
if default != None: | |
field = sys.argv[index] | |
del sys.argv[index] | |
return field | |
else: | |
return True | |
else: | |
if default != None: | |
return default | |
return False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment