Last active
November 13, 2017 06:24
-
-
Save jaycody/c76204792d6e6c2cabb766437b7bd1d0 to your computer and use it in GitHub Desktop.
Basic argument-parsing code to digest input from the command line.
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
# This basic command line argument parsing code is provided and | |
# calls the handle_this() and review_that() functions | |
# inspired by google's python class! thanks! | |
def main(): | |
if len(sys.argv) != 3: | |
print 'usage: ./myscript.py {--option_1 | --option_2} file_to_get' | |
sys.exit(1) | |
option = sys.argv[1] | |
filename = sys.argv[2] | |
if option == '--option_1': | |
handle_this(filename) | |
elif option == '--option_2': | |
review_that(filename) | |
else: | |
print 'unknown option: ' + option | |
sys.exit(1) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment