how to re-import changed code?

Jeff Shannon jeff at ccvcorp.com
Fri Oct 15 22:07:12 CEST 2004


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)
>  
>

What you're looking for is the reload() function.

Normally, an imported module is cached by the interpreter, and 
subsequent imports go straight to the cache without checking whether the 
file has changed or not.  If you reload(), that specifically clears the 
cache and imports from the (current) disk file again.

Jeff Shannon
Technician/Programmer
Credit International




More information about the Python-list mailing list