blog.finxter.com blog.finxter.com

Python’s __import__() Function — Dynamically Importing a Library By Name

Python’s built-in “dunder” function __import__() allows you to import a library by name. For example, you may want to import a library that was provided as a user input, so you may only have the string name of the library. For example, to import the NumPy library dynamically, you could run __import__('numpy'). In this tutorial, I’ll show you how to use the __import__() function to customize the import behavior of your Python...