by fuzzythinker · 9y ago · 0 comments
class Obj():
def __init__(self, d):
self.__dict__ = d
d = Obj({
'a': 1,
'b': 2,
})
print(d.a) from types import SimpleNamespace
d = SimpleNamespace(a=1, b=2)
print(d.a) my_dict = {
'a': 1,
'b': 2
}
d = SimpleNamespace(**my_dict)
print(d.a)Although there is this PyCon talk from 2012 advocating not to write classes if there is only one or two methods. [1]