MCPcopy Create free account
hub / github.com/datapane/datapane / load

Function load

python-client/src/datapane/_vendor/bottle.py:3587–3604  ·  view source on GitHub ↗

Import a module or fetch an object from a module. * ``package.module`` returns `module` as a module object. * ``pack.mod:name`` returns the module variable `name` from `pack.mod`. * ``pack.mod:func()`` calls `pack.mod.func()` and returns the result. The last form a

(target, **namespace)

Source from the content-addressed store, hash-verified

3585
3586
3587def load(target, **namespace):
3588 """ Import a module or fetch an object from a module.
3589
3590 * ``package.module`` returns `module` as a module object.
3591 * ``pack.mod:name`` returns the module variable `name` from `pack.mod`.
3592 * ``pack.mod:func()`` calls `pack.mod.func()` and returns the result.
3593
3594 The last form accepts not only function calls, but any type of
3595 expression. Keyword arguments passed to this function are available as
3596 local variables. Example: ``import_string('re:compile(x)', x='[a-z]')``
3597 """
3598 module, target = target.split(":", 1) if ':' in target else (target, None)
3599 if module not in sys.modules: __import__(module)
3600 if not target: return sys.modules[module]
3601 if target.isalnum(): return getattr(sys.modules[module], target)
3602 package_name = module.split('.')[0]
3603 namespace[package_name] = sys.modules[package_name]
3604 return eval('%s.%s' % (module, target), namespace)
3605
3606
3607def load_app(target):

Callers 4

decoratorMethod · 0.70
load_moduleMethod · 0.70
load_appFunction · 0.70
runFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected