How do I create objects on the fly in Python? I often want to pass information to my Django templates which is formatted like this:
{\'test\': [a1, a2, b2],
The code below also require a class to be created however it is shorter:
>>>d = {'test':['a1','a2','b2'], 'test2':'something else', 'test3':1} >>> class Test(object): ... def __init__(self): ... self.__dict__.update(d) >>> a = Test() >>> a.test ['a1', 'a2', 'b2'] >>> a.test2 'something else'