I have a list of names of modules such as ["module1", "module2", "module3"] this list can be ["module1", "module2", "module3"] . Question: how to import a module whose name matches the text of the list item. Example:

 import modules_my[0] 

Are there any working methods?

  • see importlib - Slava Zhuyko

1 answer 1

You can use the importlib module (In Py3, it has even more functions).

 import importlib np = importlib.import_module('numpy') np.random.random() >>> 0.10880518874684186 
  • now everything works, very grateful - Mihail Ris