Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (47.6k points)

I know it can be done, but I never remember how.

How can you re import a module in python? The scenario is as follows: I import a module interactively and tinker with it, but then I face an error. I fix the error in the .py file and then I want to re-import the fixed module without quitting python. 

How can I do it?

1 Answer

0 votes
by (106k points)

You can re-import a module in python, by using the importlib and its function reload. 

import importlib

importlib.reload(some_module)

If you are using python 3.2 or 3.3 you can use the following code:-

import imp

imp.reload(module)

Browse Categories

...