|
import_relative(file, what, globals=None, locals=None, names=None)
Imports a module located relative to another
| file | file attribute of the importing module
| what| the module to import
| globals| if desired, the globals dict of the module importing to update
| locals| if desired, the locals dict of the module importing to update
| names| names to import (only used if locals or globals is passed aswelll)
|
The semantics for the module to import follow the someday to come
python relative import syntax. To import a 'foo' module residing
lower in the hirarchy use: '.pck.foo'. To import a 'foo' module
residing higher in the hirarchy use: '..pkg.foo', where each dot
is one level up in the hirarchy.
| | | |
Sample:
foo = import_relative(__file__, '.foo')
# imports the 'foo' module residing in the same folder as
# the module __file__
foo = import_relative(__file__, '.foo', globals=globals(), names=('func1', ))
# imports the 'func1' function of the module 'foo' into the modules
# global namespace
|
|