I use Python 2.5, Win32 MSI release.

Setting attributes on an empty object does not work:

>>> a=object()

>>> a.x=1
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'object' object has no attribute 'x'

>>> setattr(a, 'x', 1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'object' object has no attribute 'x'

>>> a.__setattr__('x', 1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'object' object has no attribute 'x'

The dir(a) function indicates, that the object instance has no __dict__ 
attribute.

However using an empty new style class works fine:

>>> class C(object): pass
...
>>> c=C()
>>> setattr(c, 'x', 1)
>>>

The dir(c) function indicates, that the C instance has a __dict__ attribute.

Python 2.5 manual says:

"Return a new featureless object. object is a base for all new style classes. 
It has the methods that are common to all instances of new style classes."

Why don't have an object() instance a __dict__ attribute by default?

This may need some explanation in the Python manual.

Viktor
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to