Overriding "__setattr__" of a module - possible?

Christian Heimes lists at cheimes.de
Wed Jun 16 04:23:42 EDT 2010


> There aren't any; modules do not follow the class object protocol. They
> are simple types with a __dict__ (which you can't change, either, so no
> replacing it with a dict that implements __setattr__).

You are wrong, my friend. :)

Modules follow the new style class and instance protocol. Modules aren't
classes but instances of the internal module type. Since you can't
overwrite magic methods on instances of new style classes you can't
overwrite __setattr__ on module level, too.

Christian




More information about the Python-list mailing list