Categories
Python Answers

How to import module from string variable with Python?

Spread the love

Sometimes, we want to import module from string variable with Python.

In this article, we’ll look at how to import module from string variable with Python.

How to import module from string variable with Python?

To import module from string variable with Python, we can use the importlib.imnport_module method.

For instance, we write

import importlib

i = importlib.import_module("matplotlib.text")

to call importlib.import_module with the module name string to import the module.

Conclusion

To import module from string variable with Python, we can use the importlib.imnport_module method.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *