1

A lot of times, i try to import a python file as a module in interactive mode, but i notice an error in one of the functions, so i have to go and fix it, then i have to quit() python in interepter and re open it, then re-import the module which takes a good amount of time in my very slow pc, And if i notice another error then it is just a tudious task.

How can i delete a module from the python interepter without completely deleting it (allowing it to be re imported later) without restarting 'python'?

  • Some more comments on this question can be found here: http://stackoverflow.com/questions/437589/how-do-i-unload-reload-a-python-module – Robert Redl Nov 18 '14 at 12:53

1 Answers1

0

You can reload a module after making changes:

reload(my_module)

From the documentation:

Reload a previously imported module. The argument must be a module object, so it must have been successfully imported before. This is useful if you have edited the module source file using an external editor and want to try out the new version without leaving the Python interpreter. The return value is the module object (the same as the module argument).

Andy
  • 49,085
  • 60
  • 166
  • 233