Is it ok to use --> obj = object()?
aurora
aurora00 at gmail.com
Sun Oct 17 19:23:24 EDT 2004
Sometimes I find it useful to create an instance of some dummy class so
that I can bind abitrary attributes to it. I sometimes prefer this to
mapping object.
>>> class A: pass
...
>>> a = A()
>>> a.x = 1
>>> class B(object): pass
...
>>> b = B()
>>> b.x = 1
Rather that creating a dummy class, why not just instantiate from the
object class? However:
>>> obj = object()
>>> obj.x = 1
Traceback (most recent call last):
File "<stdin>", line 1, in ?
AttributeError: 'object' object has no attribute 'x'
I know I must have misunderstood something. Can you tell me what was wrong?
More information about the Python-list
mailing list