like the title says, I have a parser that has to do 2 things on an argument,
- it has to append a const to a list (a list that gives the program all the functions it has to process)
- it has to add the value after this argument to a variable, so it can be used later
some code of the parser (will fail, as defining 2 times '-copy' wont work:
parser = argparse.ArgumentParser(formatter_class=argparse.RawTextHelpFormatter, description="""some help text""") # ... more arguments, but not a problem parser.add_argument('-ls','--list',action='append_const', dest='tasks',const=ls, help='outputs the filelocation if match was found') parser.add_argument('-copy', action='append_const', dest='tasks',const=copy, help='copies the file to the given location if a match was found') parser.add_argument('-copy', dest='copyLocation', help='outputs the filelocation if match was found') anyone an idea of how to work around this and make the -copy argument do both a store and a append_const?
I know I could just 'postprocess' the args and check if there is a -copy in it, and if so then add the function copy to the list tasks. But this seams like a workaround, so I hoped there is a better way of doing things without postprocessing the arguments.