Here is some simple code that allows you to call different functions based on user provided options.

There are more robust tools out there but if you just want something quick this should be enough.

# 3.x.py

from os import sys

def run_option_a():
    print("Hello from option A !")

def run_option_b():
    print("Hello from option B !") 

if __name__ == "__main__":

    if len(sys.argv) >= 2:
        if sys.argv[1] == '-a':
            run_option_a()

        elif sys.argv[1] == '-b':
            run_option_b()

        else:
            print('Unrecognized command')
    else:
        print ('* Please enter -a for option A or -b for option B')

# Usage:
    python file_name.py -a
    python file_name.py -b

January 1, 2017 Python


Previous post
Asymptotic notation Khan Academy has a great explanation on the need of Asymptotic notation. Here is the best part. When we drop the constant coefficients and the less
Next post
Avoid Module Level Imports Can’t remember where I read this but it’s good to keep in mind why module level imports should be avoided. Having imports later in the file can be