Python's argparse: How to use keyword as argument's name

后端 未结 3 1961
鱼传尺愫
鱼传尺愫 2021-01-18 00:30

lambda has a keyword function in Python:

f = lambda x: x**2 + 2*x - 5

What if I want to use it as a variable name? Is there an

3条回答
  •  梦谈多话
    2021-01-18 00:42

    argparse provides destination functionality for arguments if the long option name is not the desired attribute name for the argument.

    For instance:

    parser = argparse.ArgumentParser()
    parser.add_argument("--lambda", dest="function")
    
    args = parser.parse_args()
    
    print(args.function)
    

提交回复
热议问题