[Tutor] argparse: how to use the returned Namespace object?

Mac Ryan quasipedia at gmail.com
Fri Nov 5 01:40:59 CET 2010


On Fri, 2010-11-05 at 00:17 +0000, Walter Prins wrote:
> 
> 
> On 4 November 2010 23:20, Mac Ryan <quasipedia at gmail.com> wrote:
>         My question boils down to: how can I expand the Namespace
>         object in
>         order to get a list of keyword arguments?
> 
> If "ns" is your Namespace object, then use ns.__dict__, which you can
> directly pass to your commands, e.g.
> 
> do_stuff(**ns.__dict__)
> 
> I'll post a more complete answer if this isn't clear/obvious.
> 
> HTH

Thank you Walter. I got it and it works! :)

I have a follow-up question, though.

I had previously already inspected "ns.__dict__" with the "dir()"
function, but couldn't (and can not) see my parameters neither with
"dir(ns.__dict__)" nor with "dir(ns.__dict__.items)". This is clearly an
indication that I misunderstand what the __dict__ is and how it works.

Yet if I do a dir() on an instance of an object, it does work as
expected, returning all attributes of that object.

Could you (on anybody else!) help me undertand what I fail to grasp?

Thank you!
Mac.






More information about the Tutor mailing list