[IPython-user] how to use @dreload after a @run?

Fernando Perez Fernando.Perez at colorado.edu
Thu May 20 11:34:03 CDT 2004


Maciej Kalisiak wrote:
> On Mon, May 17, 2004 at 12:13:13AM -0400, Fernando Perez wrote:
> 
> Well, when I try "dreload" or "dreload()" (after a "@run foo.py"), I get
> 
>     In [3]: dreload()
>     ---------------------------------------------------------------------------
>     TypeError                                 Traceback (most recent call last)
> 
>     /home/mac/<console>
> 
>     TypeError: reload() takes at least 1 argument (0 given)

Yes, you need a module name as an argument.

> Also, as I understand it, the global scope of foo.py becomes the global scope
> of IPython, and yet when I try "dreload math_extra" (the latter is directly
> imported by foo.py), I get
> 
>     In [4]: dreload math_extra
>     ------> dreload(math_extra)
>     ---------------------------------------------------------------------------
>     NameError                                 Traceback (most recent call last)
> 
>     /home/mac/academic/kinodyn_with_macro/<console>
> 
>     NameError: name 'math_extra' is not defined

Well, it works for me here:

In [4]: cat foo.py
import bar

In [5]: cat bar.py
a=1

In [6]: run foo

In [7]: dreload bar
------> dreload(bar)
Reloading bar
Out[7]: <module 'bar' from 'bar.pyc'>

Is it possible that math_extra is not at the top-level, or is being imported 
by foo with another name, or with a 'from math_extra import *'?  The 
'math_extra' name must exist at the top-level for dreload() to find it.  Type 
'math_extra?' and show me what it says, as well as the import-related part of 
foo.py.

Cheers,

f




More information about the IPython-user mailing list