Is it ok to use --> obj = object()?

aurora aurora00 at gmail.com
Mon Oct 18 01:23:24 CEST 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