Testing changes to Python code on the fly: reload() + alternatives?

Terry Reedy tjreedy at udel.edu
Wed Apr 13 00:49:27 CEST 2011


On 4/12/2011 3:26 PM, Keith wrote:

> 1) Is it possible to reload a class using the reload() method?

Yes, but instances of the old version will remain instances of the old 
version, which will not go away until all its instances and other 
references go away. So reload is deceptive, which is why it was 
semi-hidden away in 3.x in the inspect module.

 >>> class C: pass
 >>> c = C()
 >>> class C: pass # simulate reload
 >>> c2 = C()
 >>> id(c.__class__)
16018776
 >>> id(c2.__class__)
16039320

> 2) More generally though, what is the best way to go about testing changes to code

Restart from the beginning.

-- 
Terry Jan Reedy




More information about the Python-list mailing list