Reload Function

By default, Python only imports a module once per session - if you edit that module's file afterward, your program keeps using the old, already-loaded version unless you explicitly reload it.

The Problem reload() Solves

This is especially noticeable when working interactively, such as in a Jupyter Notebook - you import your own custom module, make changes to its code, but importing it again does nothing because Python remembers it's already loaded.

Using importlib.reload()

import importlib
import my_module

# ... you edit my_module.py while your session is still running ...

importlib.reload(my_module)   # forces Python to re-read the updated file

Calling reload() tells Python to execute the module's code again from scratch, picking up any changes you made without needing to restart your entire Python session or notebook kernel.

reload() is primarily a development and debugging convenience. In production scripts that run once and exit, it's rarely needed, since the module is naturally loaded fresh every time the script runs.

Coming Up Next

Next, you'll get an overview of some of the most important and frequently used modules in the Python ecosystem.

Ready to Master Data Science?

Join Uncodemy's Data Science Course and build real, job-ready skills with expert mentors.

Explore Course