how to re-import changed code?

Andrew Durdin adurdin at gmail.com
Thu Oct 21 18:42:55 EDT 2004


On Sat, 16 Oct 2004 00:47:36 +0200, wolfgang.stoecher at profactor.at
<wolfgang.stoecher at profactor.at> wrote:
> Hi,
> 
> another beginner's question:
> when I import a module, change the corresponding textfile and try to
> import the same module again, it looks like the internal code does not
> change (the source-line in an error-message is up to date, however!). Also
> del module before import and deleting the .pyc file do not help! How to
> realize a fast edit-try-cycle? (btw: I am using python 2.2 under windows)

You can use the reload() builtin:

>>> help(reload)
Help on built-in function reload:

reload(...)
    reload(module) -> module

    Reload the module.  The module must have been successfully imported before.

For example:

>>>import mymodule
>>># Change mymodule.py here
>>>reload(mymodule)



More information about the Python-list mailing list