I am having little difficulty with argparse, and I would appreciate if somebody could advise on following two problems:
1) my script takes several commnad line arguments, one of them is --color. I would like argparse to enforce the following syntax: --color=True and not tolerate syntax such as: --color True.
parser = argparse.ArgumentParser()
parser.add_argument('--color', nargs=1, default=True)
2) Another option I am using is -i
parser.add_argument('-i','--ignorecase', action='store_true')
args = parser.parse_args()
depending whether True or False, re.compile will use flags=re.IGNORECASE or flags=0
if (args.ignorecase == True):
CASE_SENSITIVITY=re.IGNORECASE
else:
CASE_SENSITIVITY=0
pattern = re.compile('my_pattern', flags=CASE_SENSITIVITY)
is there any simpler way to assign the value to CASE_SENSITIVITY ? Perhaps inside the parser.add_argument, so that I can avoid the multiple steps, if else, and so on ?