[SciPy-user] Ipython "run"
Howey, David A
d.howey at imperial.ac.uk
Wed Aug 24 13:34:21 EDT 2005
thanks for the tips. 'Learning Python' (from O'Rielly - the daddy!) agrees... :-) 'from' and 'reload' don't play together, apparantly.
I'd better go and modify some code...
Dave
-----Original Message-----
From: scipy-user-bounces at scipy.net on behalf of Fernando Perez
Sent: Wed 24/08/2005 17:48
To: SciPy Users List
Subject: Re: [SciPy-user] Ipython "run"
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
N.foo
N.bar...
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):
foo(bar)
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/<console>
/home/fperez/test/nsp.py in f()
1 from Numeric import *
2
3 def f():
----> 4 array = array
5 return array([1,2,3])
UnboundLocalError: local variable 'array' referenced before assignment
Cheers,
f
_______________________________________________
SciPy-user mailing list
SciPy-user at scipy.net
http://www.scipy.net/mailman/listinfo/scipy-user
-------------- next part --------------
A non-text attachment was scrubbed...
Name: winmail.dat
Type: application/ms-tnef
Size: 3403 bytes
Desc: not available
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20050824/739f6c24/attachment.bin>
More information about the SciPy-User
mailing list