I want to add a debug print statement test, if I enable --verbose from the command line and if I have the following in the script.
logger.info(\
Here is a more concise method, that does bounds checking, and will list valid values in help:
parser = argparse.ArgumentParser(description='This is a demo.')
parser.add_argument("-l", "--log", dest="logLevel", choices=['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'], help="Set the logging level")
args = parser.parse_args()
if args.logLevel:
logging.basicConfig(level=getattr(logging, args.logLevel))
Usage:
demo.py --log DEBUG