namespaces

Peter Otten __peter__ at web.de
Tue Aug 9 09:35:19 EDT 2005


Paolino wrote:

> Why descriptor mechanism doesn't apply to modules?

Because modules are instances of the module class and the descriptor has to
be defined in the class in order to work with the instance. E. g.:

>>> import sys
>>> class Descr(object):
...     def __get__(*args): print "__get__%r" % (args,)
...
>>> module = type(sys)
>>> class Module(module):
...     descr = Descr()
...
>>> m = Module("noname")
>>> m.descr
__get__(<__main__.Descr object at 0x4029372c>, <module 'noname' (built-in)>,
<class '__main__.Module'>)
>>>

Peter




More information about the Python-list mailing list