无法识别的参数:True

Abh*_*tia 4 python argparse

代码:

if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='Build dataset')
    parser.add_argument('--do_plot', action="store_true",
                        help='Plot the images')
    args = parser.parse_args()
Run Code Online (Sandbox Code Playgroud)

错误:

if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='Build dataset')
    parser.add_argument('--do_plot', action="store_true",
                        help='Plot the images')
    args = parser.parse_args()
Run Code Online (Sandbox Code Playgroud)

Jor*_*wis 8

正如您所配置的那样,该--do_plot选项不带任何参数。store_truein 中的参数表示argparse该选项的存在将自动存储True在相应的变量中。

因此,为了防止出现问题,请停止传递True--do_plot.