0

I have a Python 3 program that uses the argparse module to collect command line arguments, and I would like to add a feature to my program so that arguments may be taken which set an arbitrary internal variable to a value at runtime.

For example: ./program.py --regular-option +myvar=apples +othervar=oranges

Is this something that argparse can handle? Otherwise, how do I prevent argparse from thinking a nonexistent option has been passed while I manually extract these options from sys.argv?

Sei Satzparad
  • 1,137
  • 1
  • 9
  • 12
  • `argparse` does not naturally handle arbitrary key:value pairs. But we have discussed, in previous questions, possible solutions: https://stackoverflow.com/questions/34384865/using-a-variable-keyword-for-an-optional-argument-name-with-python-argparse – hpaulj Jan 28 '18 at 04:28
  • Thank you, the keywords I was searching with didn't find that. – Sei Satzparad Jan 28 '18 at 04:36
  • I decided to handle the problem by processing and removing arguments starting with a "+" from sys.argv before invoking Argparse. – Sei Satzparad Jan 28 '18 at 04:57

0 Answers0