anonymous-types

Create an anonymous class instance in python

Create an anonymous class instance in python Question: Sometimes I need to create an anonymous class instance in python, just like c#: var o = new {attr1="something", attr2=344}; but in python I do it in this way: class Dummy: pass o = Dummy() o.attr1 = ‘something’ o.attr2 = 344 # EDIT 1 print o.attr1, o.attr2 …

Total answers: 5

Is it possible to create anonymous objects in Python?

Is it possible to create anonymous objects in Python? Question: I’m debugging some Python that takes, as input, a list of objects, each with some attributes. I’d like to hard-code some test values — let’s say, a list of four objects whose “foo” attribute is set to some number. Is there a more concise way …

Total answers: 13