![](https://secure.gravatar.com/avatar/f71f5b898ff50fe74a20646643b50795.jpg?s=120&d=mm&r=g)
Perhaps someone could share their experience using the magic command %run in Ipython? I'm just testing it out, and unfortunately it doesn't seem to do a full reload of all imported modules etc. IDLE's <F5>, on the other hand, does. This is annoying! Any tips? Dave -----Original Message----- From: scipy-user-bounces@scipy.net [mailto:scipy-user-bounces@scipy.net] On Behalf Of Fernando Perez Sent: 13 July 2005 17:42 To: SciPy Users List Subject: Re: [SciPy-user] wxpython Howey, David A wrote:
yeah, I've got it running in colour.. I just meant the 'inline' colour
changes as you type
also, what editor do you use with ipython? I quite liked the idle built in editor
You can use any editor you want, as ipython has very poor editing capabilities (limited to single-line changes). Some users like to call %edit with ipython, which will invoke your $EDITOR, try %edit? for more info. I personally don't like %edit, and my normal modus operandi is to run Xemacs with my files open, along with an ipython session where I use '%run foo' over and over as I modify the file foo.py. I find this to be a good balance: I get a good editor for the heavy lifting, and in the interactive ipython session I get good tracebacks, %pdb debugging, the ability to inspect objects resulting from my runs, and no expensive reinitialization of the interpreter for each test (this can be a HUGE deal if you are using complex/large libraries like scipy or VTK). Cheers, f _______________________________________________ SciPy-user mailing list SciPy-user@scipy.net http://www.scipy.net/mailman/listinfo/scipy-user
![](https://secure.gravatar.com/avatar/73f4e1ffd23622a339c1c9303615d7fe.jpg?s=120&d=mm&r=g)
"Howey," == Howey, David A <d.howey@imperial.ac.uk> writes:
Howey> Perhaps someone could share their experience using the Howey> magic command %run in Ipython? I'm just testing it out, Howey> and unfortunately it doesn't seem to do a full reload of Howey> all imported modules etc. IDLE's <F5>, on the other hand, Howey> does. This is annoying! Any tips? Dave One man's annoyance, another man's feature. When you are *using* really big modules that can take tens of seconds to import, it's nice not to have to pay the cost of the reload with each run. When you are *developing* modules that the script imports, it's a pain not to have your code reloaded. A good rule of thumb is to use run when you are using a module, not when you are developing it. You can achieve the desired behavior by doing In [7]: !python myscript.py Fernando, would it be useful to have a -python or -force or -reload option to run which produces the equivalent of the above. If only for didactic purposes, it would make it clearer in the docstring that a reload is not taking place. Perhaps the current run documentation is a bit misleading, where it reads: This is similar to running at a system prompt: $ python file args JDH
![](https://secure.gravatar.com/avatar/4dabc91d1db962b0d8cd632c4e0f37ae.jpg?s=120&d=mm&r=g)
If you only want to reload one or two modules that you are developing, you can try two approaches. One is to use the %macro command to combined reload with run. The other is to hard code into your scripts to reload modules that you are developing after you have imported them. Fernando may have better advice. Ryan Howey, David A wrote:
Perhaps someone could share their experience using the magic command %run in Ipython? I'm just testing it out, and unfortunately it doesn't seem to do a full reload of all imported modules etc. IDLE's <F5>, on the other hand, does. This is annoying! Any tips? Dave
-----Original Message----- From: scipy-user-bounces@scipy.net [mailto:scipy-user-bounces@scipy.net] On Behalf Of Fernando Perez Sent: 13 July 2005 17:42 To: SciPy Users List Subject: Re: [SciPy-user] wxpython
Howey, David A wrote:
yeah, I've got it running in colour.. I just meant the 'inline' colour
changes as you type
also, what editor do you use with ipython? I quite liked the idle built in editor
You can use any editor you want, as ipython has very poor editing capabilities (limited to single-line changes). Some users like to call %edit with ipython, which will invoke your $EDITOR, try %edit? for more info.
I personally don't like %edit, and my normal modus operandi is to run Xemacs with my files open, along with an ipython session where I use '%run foo' over and over as I modify the file foo.py. I find this to be a good balance: I get a good editor for the heavy lifting, and in the interactive ipython session I get good tracebacks, %pdb debugging, the ability to inspect objects resulting from my runs, and no expensive reinitialization of the interpreter for each test (this can be a HUGE deal if you are using complex/large libraries like scipy or VTK).
Cheers,
f
_______________________________________________ SciPy-user mailing list SciPy-user@scipy.net http://www.scipy.net/mailman/listinfo/scipy-user
_______________________________________________ SciPy-user mailing list SciPy-user@scipy.net http://www.scipy.net/mailman/listinfo/scipy-user
![](https://secure.gravatar.com/avatar/5a7d8a4d756bb1f1b2ea729a7e5dcbce.jpg?s=120&d=mm&r=g)
Ryan Krauss wrote:
If you only want to reload one or two modules that you are developing, you can try two approaches. One is to use the %macro command to combined reload with run. The other is to hard code into your scripts to reload modules that you are developing after you have imported them.
Fernando may have better advice.
Not really: what you describe is pretty much what I always do. Many of my 'top-level' scripts which use modules I'm in the middle of modifying, look like: import foo reload(foo) foo.dostuff() It's not terribly elegant, but it works. And as John said, wholesale reloading of everything can be very expensive, so it's not a good idea as a default. Having said that, I should mention dreload(), part of ipython. It _tries_ to do a recursive ('deep') reload of a given module, and I know many ipython users love it. Given that there is no way for any tool to guess, out of the many modules in memory, which ones the user actually _wants_ reloaded, I think the manual solution is not all that bad. I should finally add that extension modules can NOT be reoloaded, to the best of my knowledge. I just checked what Idle does: it runs the user's code in a separate process altogether: fperez 10662 1.4 0.9 15192 9936 pts/15 S+ 09:54 0:00 /usr/bin/python /usr/bin/idle fperez 10673 1.0 0.5 13884 5360 pts/15 Sl+ 09:55 0:00 /usr/bin/python -c __import__('idlelib.run').run.main(True) 8833 And after hitting F5: fperez 10662 0.9 0.9 15192 9936 pts/15 S+ 09:54 0:00 /usr/bin/python /usr/bin/idle fperez 10691 1.6 0.5 13884 5360 pts/15 Sl+ 09:55 0:00 /usr/bin/python -c __import__('idlelib.run').run.main(True) 8833 Notice the process number for the user code execution has just changed. In summary, Idle's F5 is equivalent to John's solution, to use !python foo.py. Unfortunately because this runs in a separate process, you lose nice exception tracebacks, integrated debugging, etc. It would not be impossible to write a little magic that does something similar for ipython, while retaining the settings for exceptions, pdb and other things. I'll keep it in mind for a future release, unless somebody beats me to it. Cheers, f
participants (4)
-
Fernando Perez
-
Howey, David A
-
John Hunter
-
Ryan Krauss