Helper to enable simple lazy module import.
‘Lazy’ means the actual import is deferred until an attribute is requested from the module’s namespace. This has the advantage of allowing all imports to be done at the top of a script (in a prominent and visible place) without having a great impact on startup time.
Copyright (c) 1999-2005, Marc-Andre Lemburg; mailto:email@example.com See the documentation for further information on copyrights, or contact the author. All Rights Reserved.
- class nltk.lazyimport.LazyModule¶
Lazy module class.
Lazy modules are imported into the given namespaces whenever a non-special attribute (there are some attributes like __doc__ that class instances handle without calling __getattr__) is requested. The module is then registered under the given name in locals usually replacing the import wrapper instance. The import itself is done using globals as global namespace.
Example of creating a lazy load module:
ISO = LazyModule(‘ISO’,locals(),globals())
Later, requesting an attribute from ISO will load the module automatically into the locals() namespace, overriding the LazyModule instance:
t = ISO.Week(1998,1,1)
- __init__(name, locals, globals=None)¶
Create a LazyModule instance wrapping module name.
The module will later on be registered in locals under the given module name.
globals is optional and defaults to locals.