Dynamically importing modules PREMIUM

Series: Modules
Trey Hunner smiling in a t-shirt against a yellow wall
Trey Hunner
4 min. read Watch as video Python 3.8—3.12
Python Morsels
Watch as video
03:47

Let's talk about importing modules dynamically in Python.

This is a big topic that could involve a few different things, and all of them are a little bit weird, so we're going to take a look at a few examples.

Dynamically importing a module using its name

Let's say we have a string that represents a module name, and we don't have this module name when we write our Python code, but we do have this name at runtime:

...

A Python Tip Every Week

Need to fill-in gaps in your Python skills? I send weekly emails designed to do just that.

Python Morsels
Watch as video
03:47