[SciPy-user] Newbie and Old matlab user

Fernando Perez Fernando.Perez at colorado.edu
Thu Oct 13 09:25:43 CDT 2005

Samuel GARCIA wrote:
> thank you.
> but howto deal with th case from source2 import * ?
> And the case import source2 does the reload function mean that I have to type :
> reload(source2)
> in the file source1.py
> each time I modify source2.py and then delete this line before typing :
> run source1
> in ipython
> It's llok difficult !

just to clarify a bit.  Yes, module reloading can be a bit annoying in python, 
unfortunately.  If you are working on s1.py but also on s2.py, and s1.py is 
your top-level file, the easiest solution (which I use a lot) is just to put

import s2

into s1.py.  You _don't_ have to delete the reload line, at least not until 
you know you are done with this project.  It simply means that s2 is 
re-imported on every run of s1, but that's typically not a big deal (unless s2 
is enormously complex).

If s2 further requires things which may change, it gets worse.  You can try to 
put further reload() statements down the chain, or you can try to use 
ipython's recursive reloader.  In s1:

from IPython.deep_reload import reload
import s2

This will _try_ to do a full, recursive reload of s2 and everything it needs. 
  it's slower, and not 100% reliable (in particular, extension code can't be 
reloaded), but it can be a big time saver in many cases.

Finally, the 'from s2 import *' idiom breaks all this, I think. You can try 
this, but I'm not sure it works (I think it doesn't):

import s2
from s2 import *



More information about the SciPy-user mailing list