[PYTHON] Dynamically load the module.

def lazy_loader(name):
    """Loading function, class and module lazy."""
    try:
        mod = __import__(name)
    except:
        mod_list = name.split('.')
        mod = __import__('.'.join(mod_list[:-1]))

    components = name.split('.')
    for comp in components[1:]:
        mod = getattr(mod, comp)
    return mod

Recommended Posts

Dynamically load the module.
Load the module with the same name in another location
About the Python module venv
Test the version of the argparse module
How to use the optparse module
Put the module in the Pepper app
Dynamically load json type in python
Try using the Python Cmd module
How to use the ConfigParser module
Preparing to load the original dataset
Master the weakref module in Python
pyenv + pyenv-Automatically load the virtualenv environment in the virtualenv environment
Pass the path of the imported python module
Play around with the pythonista3 ui module
[Python] Import the module one level higher
Check the path of the Python imported module
Install the Python module in any directory