what is the right way to treat Python argparse.Namespace() as a dictionary?

前端 未结 3 1346
伪装坚强ぢ
伪装坚强ぢ 2020-11-27 10:25

If I want to use the results of argparse.ArgumentParser(), which is a Namespace object, with a method that expects a dictionary or mapping-like obj

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-27 10:38

    Is it proper to "reach into" an object and use its dict property?

    In general, I would say "no". However Namespace has struck me as over-engineered, possibly from when classes couldn't inherit from built-in types.

    On the other hand, Namespace does present a task-oriented approach to argparse, and I can't think of a situation that would call for grabbing the __dict__, but the limits of my imagination are not the same as yours.

提交回复
热议问题