tags:

views:

176

answers:

3

I have been wondering about the reload() function in python, which seems like it can lead to problems if used without care.

Why would you want to reload a module, rather than just stop/start python again?

I imagine one application might be to test changes to a module interactively.

+4  A: 

I imagine one application might be to test changes to a module interactively.

That's really the only use for it. From the Python documentation:

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.

musicfreak
and you also might have variables or functions defined in the shell, and restarting it means you have to define them again
Adrian Mester
+5  A: 

reload is useful for reloading code that may have changed in a Python module. Usually this means a plugin system.

Take a look at this link:

http://www.codexon.com/posts/a-better-python-reload

It will tell you the shortcomings of reload and a possible fix.

Unknown
thanks, it was exactly this kind of class/instance question I was wondering about.
mataap
A: 

Adding a link to my new reimport module that was released yesterday. This provides a more thorough reimport than the reload() builtin. With this reimport you can be sure that class changes and function updates will get reflected in all instances and callbacks.

http://code.google.com/p/reimport/

Peter Shinners