Why my modification of source file doesn't take effect when debugging?

infidel saint.infidel at gmail.com
Fri Dec 2 11:56:49 EST 2005


> I'm using the Windows version of Python and IDLE. When I debug my .py
> file, my modification to the .py file does not seem to take effect
> unless I restart IDLE. Saving the file and re-importing it doesn't help
> either. Where's the problem?

"import" only reads the file the first time it's called.  Every import
call after that looks up the module in memory.  This is to prevent
circular dependencies between modules from creating infinite loops.
You need to use the reload() function:

>>> import foo

#change the contents of foo

>>> foo = reload(foo)




More information about the Python-list mailing list