Skip to content

Instantly share code, notes, and snippets.

@jaycody
Last active November 13, 2017 06:24
Show Gist options
  • Save jaycody/c76204792d6e6c2cabb766437b7bd1d0 to your computer and use it in GitHub Desktop.
Save jaycody/c76204792d6e6c2cabb766437b7bd1d0 to your computer and use it in GitHub Desktop.
Basic argument-parsing code to digest input from the command line.
# 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