At 07:22 PM 4/24/03 -0400, Aahz wrote: >Data descriptors on module objects. If you *really* need them, you can have them. from types import ModuleType import time, sys class ModuleWithDescriptor(ModuleType): bar = property(lambda self: time.time()) moduleFoo = ModuleWithDescriptor() # named module must be importable, but not yet imported; # parent package must be in sys.modules moduleFoo.__name__ = "mypackage.foo" sys.modules['mypacakge.foo'] = reload(moduleFoo) import mypackage.foo # watch the time change... print mypackage.foo.bar print mypackage.foo.bar I *love* new-style classes. I use the trick above for lazy module importation; a subclass of ModuleType that doesn't import itself until the first time a __getattribute__ occurs.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4