Package nltk :: Module lazyimport :: Class LazyModule
[hide private]
[frames] | no frames]

classobj_type LazyModule

source code

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)

Instance Methods [hide private]
 
__init__(self, name, locals, globals=None)
Create a LazyModule instance wrapping module name.
source code
 
__lazymodule_import(self)
Import the module now.
source code
 
__getattr__(self, name)
Import the module on demand and get the attribute.
source code
 
__setattr__(self, name, value)
Import the module on demand and set the attribute.
source code
 
__repr__(self) source code
Class Variables [hide private]
  __lazymodule_init = 0
  __lazymodule_name = ''
  __lazymodule_loaded = 0
  __lazymodule_locals = None
  __lazymodule_globals = None
Method Details [hide private]

__init__(self, name, locals, globals=None)
(Constructor)

source code 

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.