namespaces

Scott David Daniels Scott.Daniels at Acm.Org
Tue Aug 9 11:35:38 EDT 2005


Paolino wrote:
> Peter Otten wrote:
>> 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....
> Then there is no way of having descriptors at module level,as 'module' 
> class is not updatable.

Well, an entry in the dictionary "sys.modules" is what is returned by
imports, so you could either pre-replace or post-replace a module by
an object which uses the descriptor technique to get to some (but not
necessarily all) of the attributes.  Think of this technique as a
hack to get to a goal, rather than a good technique to use; good for
debugging, not so nice for production work.  If you still don't know
how to do this from this admittedly sketchy description, I'd suggest
you avoid trying it altogether.

--Scott David Daniels



More information about the Python-list mailing list