Namespace, argparse, and usage

五迷三道 提交于 2019-12-03 22:17:37
Sven Marnach
  1. The designers of arparse apparently felt it would be more convenient to access arguments as

    args.arg_name
    

    rather than

    args["arg_name"]
    

    This might be a matter of taste, though. I would have happily gone with the dictionary, especially given the fact that there is no Namespace class in the standard library, except for the one in argparse.

  2. Use a dictionary.

  3. If you really want a namespace here, you can use init_function(**args.__dict__)…but I don't recommend it.

It is easy to convert a Namespace into a dictionary using vars():

>>> vars(args)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!