import argparse
def parse():
    parser = argparse.ArgumentParser()
    parser.add_argument('--scales',help='scales',type=int,default=5)
    opt = parser.parse_args()
    return opt
if __name__ == '__main__':
    opt = parse()
    print(opt)
    opt.num = 'now two args'
    print(opt)

  结果:

Namespace(scales=5)
Namespace(num='now two args', scales=5)

note:使用argparse加载参数,在parse()方法中定义完opt后,其他地方再用到其他参数,可以直接加参数,例如

opt.num = 'now two args'

相关文章:

  • 2021-09-18
  • 2021-05-20
  • 2022-12-23
  • 1970-01-01
猜你喜欢
  • 2021-11-17
  • 2021-05-22
  • 2021-05-30
  • 2021-06-21
  • 2021-05-04
  • 2022-12-23
  • 2021-07-14
相关资源
相似解决方案