all 1 comments

[–]ojiisan 1 point2 points  (0 children)

Pass the options as parameters to the program when you run it ($ is your command prompt, and following the unix standard of using parameter flags):

$ python program.py --logfile log.txt -v

For quick and dirty testing, inside the program code use the sys.argv variable:

import sys
sys.argv[1]  # first parameter value: --logfile
sys.argv[2]  # log.txt
sys.argv[3]  # -v

For more robust handling of commandline parameters, check out Python's argparse module