import module from string variable
The __import__ function can be a bit hard to understand. If you change i = __import__(‘matplotlib.text’) to i = __import__(‘matplotlib.text’, fromlist=[”]) then i will refer to matplotlib.text. In Python 2.7 and Python 3.1 or later, you can use importlib: import importlib i = importlib.import_module(“matplotlib.text”) Some notes If you’re trying to import something from a sub-folder … Read more