Is it possible to use the name of an input, eg a yaml/dict key, on self while not knowing that key literally?
Meaning, if there were some data like:
entries = [
{'foo': 'foo 1', 'bar': 'bar 1'},
{'foo': 'foo 2', 'bar': 'bar 2'},
]
How could we do the below without explicitly preprogramming 'foo' and 'bar' to name the self variables?
class entry(object):
def __init__(self):
self.foo = entries[0]['foo']
self.bar = entries[0]['bar']
And I suppose those self assignments would not have to be named foo and bar, but at least be able to reference them as such.
setattr(self, 'foo', 'entries[0]['foo']')is equivalent toself.foo = entries[0]['foo']dict. Instead of usingobj.foo, you'd callmy_dict['foo']- so I'd just stick to yourentriesdictionaries