[IPython-user] reload question
belinda thom
bthom at cs.hmc.edu
Fri Dec 1 00:54:07 CST 2006
On Nov 28, 2006, at 10:34 PM, Fernando Perez wrote:
> [snip]
> Ideally, I'd open e.g., foo.py, into xemacs and then (re)load it into
>> iPython (py-shell buffer) via C-c RET. When I do this, it does put
>> foo into the interactive namespace. However, for doctesting, I want
>> the objects inside of foo.py to be in the namespace. To accomplish
>> this:
>>
>> from foo import *
>>
>> works. However, if I now modify foo.py in some way, I can't figure
>> out how to reload the objects into the namespace directly.
>>
>> This kind of operation seems like it might be used a lot. Is there
>> some magic command I'm missing?
>
> More like a python trick:
>
> import foo; reload(foo); from foo import *
>
> This will ensure that every time that line is run, you actually see
> the changes in foo.
Here's a related (?) question. I am editing a file in xemacs (call it
foo.py). I then Ctrl+c Ctrl+m (py-execute-import-or-reload) and
(all?) the changes are not visible in py-shell.
To be concrete, suppose I just added a new method to class Foo in
foo.py. Prior to this edit, I had used Ctrl+c Ctrl+m to access the
(old) file's contents in py-shell, after which I:
In [10]: t = foo.Foo(...)
After adding the new method to Foo and Ctr+c Ctrl+m, I recreated t:
In [11]: t = foo.Foo(...)
However, when I do:
In [12]: dir(t)
I don't see the new method's name listed!
I have also tried:
%reset
before the 2nd Ctrl+c Ctrl+m, which does not change the behavior.
What is going on?
--b
More information about the IPython-user
mailing list