Re: [Tutor] Does IPython have a "restart"?
At 07:55 AM 7/16/2008, Dick Moores wrote: I mean something equivalent to what you get when you do a Ctrl+F6 in IDLE: >>> import math >>> math.log(3) 1.0986122886681098 >>> === RESTART === >>> math.log(3) Traceback (most recent call last): File "", line 1, in math.log(3) NameError: name 'math' is not defined >>> === Got this from the ipython-user list: Use %reset: In [1]: import math In [2]: math.sin(3) Out[2]: 0.14112000805986721 In [3]: %reset Once deleted, variables cannot be recovered. Proceed (y/[n])? y In [5]: math.sin(3) --- NameError Traceback (most recent call last) /home/fperez/Desktop/ in () NameError: name 'math' is not defined Note that it is NOT the same though: idle forces a new, fresh python process, while ipython just clears your current variables. So things like reloading extension modules won't work the same way. Dick ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Does IPython have a "restart"?
On Wed, Jul 16, 2008 at 8:10 PM, Alan Gauld <[EMAIL PROTECTED]> wrote: > > "Dick Moores" <[EMAIL PROTECTED]> wrote > > Caveat: I have no experience with IPython whatsoever. > >> I have a big, 2000-line module, mycalc.py that is a collection of >> useful functions, most written by myself. I often import one or >> another function from it and use it in the Ulipad shell. Then I see >> that the function needs a small revision. I modify it in the module, >> then want to test it and then use the new version in the shell. I'd like >> to be able to do this in IPython. I have a different style of working, I guess. I do most work in files. I use an editor which will easily execute the file and show the result. For developing functions I use a unittest, still working from one or more files. So I rarely have to reload a module explicitly. > OK, If you only import the functions not the whole module reload > won't work. But how about deleting the function and then > re-importing it? Wouldn't that do it? No, you do have to reload the module. > You could even create a function to do that for you, maybe like: > > def restart(fn, mod=mycalc): > del fn > from mod import fn > return fn I'm pretty sure that won't work. It needs a reload and the default value for mod is bound at compile time so it will always be bound to the old version of mycalc. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Does IPython have a "restart"?
"Dick Moores" <[EMAIL PROTECTED]> wrote Caveat: I have no experience with IPython whatsoever. I have a big, 2000-line module, mycalc.py that is a collection of useful functions, most written by myself. I often import one or another function from it and use it in the Ulipad shell. Then I see that the function needs a small revision. I modify it in the module, then want to test it and then use the new version in the shell. I'd like to be able to do this in IPython. OK, If you only import the functions not the whole module reload won't work. But how about deleting the function and then re-importing it? Wouldn't that do it? You could even create a function to do that for you, maybe like: def restart(fn, mod=mycalc): del fn from mod import fn return fn And us it like: from mycalc import foo,restart foo(42) # oops wrong result # go edit foo foo = restart(foo) foo(42) # thats better... This is untested pseudo code but it should work with a bit of effort - eg. you may need to use the programatic mechanism for re importing Just a thought. Alan G ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Does IPython have a "restart"?
At 02:07 PM 7/16/2008, Kent Johnson wrote: On Wed, Jul 16, 2008 at 4:31 PM, Dick Moores <[EMAIL PROTECTED]> wrote: > At 10:31 AM 7/16/2008, Kent Johnson wrote: >> >> Just quit and relaunch? >> >> Kent > > Well, if that what Kent, a long-time IPython user does, I guess I'm stuck > with doing that, but I don't like it. Actually I don't do that, I suggested that you might. I don't often have a need to reset the interpreter. Why do you want to? I have a big, 2000-line module, mycalc.py that is a collection of useful functions, most written by myself. I often import one or another function from it and use it in the Ulipad shell. Then I see that the function needs a small revision. I modify it in the module, then want to test it and then use the new version in the shell. I'd like to be able to do this in IPython. What is wrong with relaunching? Hey, IPython is so cool I thought it must have what IDLE has. And relaunching takes longer. Dick ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Does IPython have a "restart"?
On Wed, Jul 16, 2008 at 4:31 PM, Dick Moores <[EMAIL PROTECTED]> wrote: > At 10:31 AM 7/16/2008, Kent Johnson wrote: >> >> Just quit and relaunch? >> >> Kent > > Well, if that what Kent, a long-time IPython user does, I guess I'm stuck > with doing that, but I don't like it. Actually I don't do that, I suggested that you might. I don't often have a need to reset the interpreter. Why do you want to? What is wrong with relaunching? Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Does IPython have a "restart"?
At 10:31 AM 7/16/2008, Kent Johnson wrote: Just quit and relaunch? Kent Well, if that what Kent, a long-time IPython user does, I guess I'm stuck with doing that, but I don't like it. Dick ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Does IPython have a "restart"?
Just quit and relaunch? Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor