How To Reload A Module In Python REPL
Feb 23, 2022
The aim of this page📝 is to share a tactical line I use when writing a python module and testing it in REPL. For that, it is required that I reimport the code upon change. However, the original import
statement does not reload the change.
- The following is valid from Python 3.4
- For the sake of velocity, I alias
importlib
toim
# PYTHON REPL (ptpython)
>>> import importlib as im
>>> im.reload(<package/module>)
- NOTE: at first, it is required to import the whole module with
import
statement and not just a function withfrom <module/package> import <function>
. Also, you need to pass the whole module/package and not just a function intoimportlib.reload()