importlib wrapper, instantiate class dynamically in one line
Project description
pyclsload
easily load classes from source files
basically just a wrapper for importlib
why?
# doesn't look
from pyclsload import load_cls
o = load_cls("somefile.py", "ThisAClass")
o.somemethod()
# better than
from importlib.util import spec_from_file_location, module_from_spec
s = spec_from_file_location("ThisAClass", "somefile.py")
o = module_from_spec(s)
s.loader.exec_module()
o.somemethod()
features
- load_cls
- init_cls
- load_dir (based on the premise that the class is called like the module)
install
pip3 install pyclsload
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
pyclsload-1.4.tar.gz
(3.0 kB
view hashes)