[SciPy-user] Ipython "run"

Fernando Perez Fernando.Perez at colorado.edu
Wed Aug 24 11:48:16 CDT 2005

Ryan Krauss wrote:
> I think this will work:
> import foo
> reload(foo)
> from foo import *
> Otherwise you may need to avoid the from foo import * during module 
> development.

I second that last suggestion as well.  I just avoid 'import *' like the 
plague, and rather use (for very heavily used modules) shorthands:

import Numeric as N


The 'import *' is IMHO only justified interactively: not only does it cause 
trouble with name clashes and reload(), but it also makes an often useful 
local optimization tricky:

def func():
   # we're about to do a long loop using some routine from N, so we make
   # it local, which is a faster lookup in python:
   foo = N.foo
   for i in range(BIG):

If you did 'from Numeric import *', you have to do a local change of name, 
since 'foo=foo' is not valid:

In [2]: f()
exceptions.UnboundLocalError                         Traceback (most recent 
call last)


/home/fperez/test/nsp.py in f()
       1 from Numeric import *
       3 def f():
----> 4     array = array
       5     return array([1,2,3])

UnboundLocalError: local variable 'array' referenced before assignment



More information about the SciPy-user mailing list