0

I have a script that receives online arguments using argparse, like this:

parser = argparse.ArgumentParser()
parser.add_argument(
    "--local", action="store_true", help=("Write outputs to local disk.")
)

parser.add_argument(
    "--swe", action="store_true", help=("Indicates 'staging' environment.")
)

args = parser.parse_args()

I want argparse to handle undeclared arguments and just to add them to the arguments dictionary, but it raises an error when I try python runner.py --local true --swe true --undeclared_argument this_is_a_test:

runner.py: error: unrecognized arguments: --undeclared_argument this_is_a_test
HuLu ViCa
  • 5,077
  • 10
  • 43
  • 93
  • 2
    Does this answer your question? [Is there any way to get argparse.ArgumentParser.parse\_args() not to exit on argument errors?](https://stackoverflow.com/questions/16004901/is-there-any-way-to-get-argparse-argumentparser-parse-args-not-to-exit-on-argu) – Julia Dec 30 '22 at 18:56
  • 2
    Does this answer your question? [Python argparse ignore unrecognised arguments](https://stackoverflow.com/questions/12818146/python-argparse-ignore-unrecognised-arguments) – Nick ODell Dec 30 '22 at 18:56

0 Answers0