import_with_new_modules(module_name,
replacement_modules={})
| source code |
This is a nifty function that allows your modules to inherit from each
other maintaining upward compatibility with regard as (for instance) orm2
based data models.
Example:
>>> import model2
>>> controllers1 = import_with_new_modules('mytest.sub.controllers1',
{'model1': model2})
>>> email = controllers1.make_email()
>>> print email.__module__
model2
The controllers1.py module was written for a datamodel stored in the
model1.py module in the same package. So it imports it. Now, the function
calls above will import controllers1 with model2 as its datamodel. Of
course the new module must be a super set of the old for this to work.
(In this example the email class has been extended by an attribute.)
-
- Parameters:
module_name - The name of the module to import (including package
name(s))
replacement_modules - A dictionary mapping module names (<b>as they are
imported by the module references by module_name</b>) and
the module object it is supposed to be replaces with.
|