An empty object with dynamic attributes (expando)

dmtr dchichkov at gmail.com
Thu Jun 3 17:00:11 EDT 2010


How can I create an empty object with dynamic attributes? It should be
something like:

>>> m = object()
>>> m.myattr = 1

But this doesn't work. And I have to resort to:

>>> class expando(object): pass
>>> m = expando()
>>> m.myattr = 1

Is there a one-liner that would do the thing?

-- Cheers, Dmitry



More information about the Python-list mailing list