Dynamically/Lazily import python module on run-time. Also enables easy to use import path name.
Project description
Lets you dynamically/lazily import python module on run-time. Also enables easy to use import path name.
Example
./example/sample/__init__.py
from dynamic_import import importer # Static Importer from .direct import static # Note # This is to demonstrate that you can still import modules directly # before "importer()" is called. # Dynamic Importer importer( __package__, { '.one': ('a', 'b', 'c'), # same as ```from .one import a, b, c``` '.two': ('x', 'y', 'z'), # same as ```from .two import x, y, z``` } )
./example/example_1.py
# Static Import #1 # ---------------- from sample import static print(static()) print() # Note # Only "sample" & "sample.direct" modules are loaded at this point. # Dynamic Import #1 # ----------------- from sample import a, b, c print(a()) print(b()) print(c()) print() # Note # Now "sample", "sample.direct" & "sample.one" modules are loaded at this point. # Dynamic Import #2 # ----------------- from sample import x, y, z print(x()) print(y()) print(z()) # Note # All "sample", "sample.direct", "sample.one" & "sample.two" modules are loaded.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
dynamic_import-0.9.1.tar.gz
(3.5 kB
view hashes)
Built Distribution
Close
Hashes for dynamic_import-0.9.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bdb8a7225a84813bc255590556f5488ae894c4fa0b88621c60a7f4daf699172a |
|
MD5 | 7da6b7b401d7ae2af6641dbf207f4c1f |
|
BLAKE2-256 | 14bfa55bbedd9bc73f88f20acbea36aba70bb0c3862607b0720c498d1f82263e |