[issue34827] Make argparse.NameSpace iterable

paul j3 report at bugs.python.org
Fri Sep 28 14:50:44 EDT 2018


paul j3 <ajipanca at gmail.com> added the comment:

As documented in https://docs.python.org/3/library/argparse.html#the-namespace-object

you can create your own 'namespace' class, that does everything you want and more.  argparse makes very few assumptions about the object - using getattr, setattr, and hasattr where possible.

All that the argparse.Namespace class adds to a plain object is the ability to set initial attributes, and to display them in a pretty way.

Look at Namespace.__repr__ to see how it accesses its attributes.

For a function with a

    fn(*args, **kwargs)

signature, a namespace 'ns', can be passed in in 2 ways:

   fn(*ns._get_kwargs(), **ns.__dict__)

----------
nosy: +paul.j3

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue34827>
_______________________________________


More information about the Python-bugs-list mailing list