python 系统退出:2,参数=解析器,parse_args()错误

piv4azn7  于 2022-12-25  发布在  Python
关注(0)|答案(1)|浏览(217)

我该怎么补救呢?

parser = argparse.ArgumentParser()
parser.add_argument("mode", help="Trains or tests the CNN", nargs="*", choices=["train", "continue", "test", "confusionmatrix", "vote", "slice"])
parser.add_argument("--resume", help="The version to continue training from", required=False, default=False)
parser.add_argument("--epochs", help="The number of epochs to finish training from", type=int, required=False, default=False)

args = parser.parse_args()

print("args", args)

我试过了

*args, unknown = parser.parse_known_args()

但没有用

zf9nrax1

zf9nrax11#

参数值不能为空。如果您的正确值是其中之一[“train”,“continue”,“test”,“confusionmatrix”,“vote”,“slice”],则必须如下所示:

parser.add_argument("--mode", help="Trains or tests the CNN", nargs="*", required=False, default='confusionmatrix')

您可以将“confusionmatrix”替换为其中的任何一个[“train”、“continue”、“test”、“confusionmatrix”、“vote”、“slice”]
如果出现系统退出:2你可以这样试试:

parser = argparse.ArgumentParser()
parser.add_argument("--mode", help="Trains or tests the CNN", nargs="*", required=False, default='confusionmatrix')
parser.add_argument("--resume", help="The version to continue training from", required=False, default=False)
parser.add_argument("--epochs", help="The number of epochs to finish training from", type=int, required=False, default=False)
parser.add_argument("-f", required=False)

args = parser.parse_args()

print("args", args)

您需要在“arg_parse.add_argument“行的末尾添加[ parser.add_argument(“-f”,required=False)]

相关问题