On 2011.07.29 10:12 AM, Ciantic wrote: >>>> class MyObject(object): > ... pass > ... >>>> my = MyObject() >>>> my.myvar = 'value' # No error! >>>> >>>> obj = object() >>>> obj.myvar = 'value' # Causes error! > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > AttributeError: 'object' object has no attribute 'myvar' > > Why simple inheritance from object does not cause errors at setattr, > yet direct init of object() does? object objects have no __dict__. User-defined objects typically do. Each child of MyObject would likely have __dict__ as well.
> I was trying to "decor" objects, lists etc with own attributes that > could be used in templates and was sadly not permitted to do so: > >>>> something = [1,2] >>>> something.myvar = 'value' > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > AttributeError: 'list' object has no attribute 'myvar' Lists have no __dict__, and AFAIK, there's no reason they should. -- CPython 3.2.1 | Windows NT 6.1.7601.17592 | Thunderbird 5.0 PGP/GPG Public Key ID: 0xF88E034060A78FCB -- http://mail.python.org/mailman/listinfo/python-list