import module from string variable

前端 未结 5 1750
离开以前
离开以前 2020-11-22 07:17

I\'m working on a documentation (personal) for nested matplotlib (MPL) library, which differs from MPL own provided, by interested submodule packages. I\'m writing Python sc

5条回答
  •  执笔经年
    2020-11-22 07:36

    importlib.import_module is what you are looking for. It returns the imported module. (Only available for Python >= 2.7 or 3.x):

    import importlib
    
    mymodule = importlib.import_module('matplotlib.text')
    

    You can thereafter access anything in the module as mymodule.myclass, etc.

提交回复
热议问题