Python Command line arguments

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.


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':

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

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

# Usage:
    python -a
    python -b