I have a set of keywords which contain a default value. Say:
a_dict =\
{'key1': 'value1'
'key2': 'value2'
... and so on ...}
I don't want to use a dict
because I find it annoying having to type:
a_dict['key2']
in order to get the keyword's value. I would like to have all of these
keywords available on a variable (say var
) so that when I press 'Tab Key' after
$var.$ I get all posible keywords. I have tried with $namedtuple$ from
$collections$ module but I run in the problem where I can't modify none of
the values of each key (because it is a touple). The good thing of
namedtuple
is that I could iterate over it, for example:
for key in var:
#do something with key
What I did is to create a class named Keys
as shown next:
class Keys(object):
def __init__(self):
self.key1 = 'value1'
self.key2 = 'value2'
... and so on...
Now when I do:
keys = Keys()
I have all the namespace available in keys.
and can modify all values of each
key. The problem is that now I cannot iterate over each key. And I don't know
how to set __getitem__
method in order to iterate over the instance keys
.
The perfect solution would be to use a namedlist
function (similar to
namedtuple
) but I don't know any similar function. Is there one?
How can I do it? Any other alternative will be wellcome. Thanks in advance.