Is there any way to get argparse.ArgumentParser.parse_args() not to exit on argument errors?
- 阅读更多 关于 Is there any way to get argparse.ArgumentParser.parse_args() not to exit on argument errors?
问题 For example: import argparse parser = arparse.ArgumentParser() # parser.add_argument(...) ... args = parser.parse_args(args_list) The problem is, parser.parse_args automatically exits if there is an error in args_list . Is there a setting that gets it to raise a friendlier exception instead? I do not want to have to catch a SystemExit and extract the needed error message from it if there is any way around it. 回答1: You could use args, unknown = parser.parse_known_args(args_list) Then, any