Bypassing __setattr__ for changing special attributes

George Sakkis george.sakkis at gmail.com
Tue Feb 20 09:09:15 EST 2007


On Feb 20, 3:54 am, "bruno.desthuilli... at gmail.com"
<bruno.desthuilli... at gmail.com> wrote:
> On 20 fév, 05:39, "George Sakkis" <george.sak... at gmail.com> wrote:
>
> > I was kinda surprised that setting __class__ or __dict__ goes through
> > the __setattr__ mechanism, like a normal attribute:
>
> But __class__ and __dict___ *are* 'normal' attributes...

Well, let alone for the fact that two leading and trailing underscores
means 'special' in python, these attributes are not exactly what they
seem to be, i.e. a 'normal' type or dict:

>>> type(object.__dict__['__class__'])
<type 'getset_descriptor'>
>>> type(type.__dict__['__dict__'])
<type 'getset_descriptor'>


George




More information about the Python-list mailing list