Using the parsed values
The parsed values by params.parse()
or params.values()
are attached to a namespace. Yes, argparse
's Namespace
. So this will be true:
from argparse import Namespace
from params import Params
params.add_param('i', default=1)
values = params.values()
isinstance(values, Namespace)
However, it is not exactly the same, meaning this is NOT true:
from argparse import Namespace as APNamespace
from params import PMNamespace
PMNamespace is APNamespace
But PMNamespace
is a subclass of APNamespace
, with following functionalities being added:
-
Subscription:
ns = PMNamespace() ns['a'] = 1 ns['a'] == 1
-
Length:
len(ns['a']) == 1
-
Key existence detection:
'a' in ns is True
You can turn a namespace into a dictionary by vars(ns)
. However, if you want to turned all the namespaces inside into dictionaries, you may need to do it recursively.