[Tutor] Importing functions in IPython

bob gailer bgailer at gmail.com
Sun Jan 22 23:51:52 CET 2012


On 1/22/2012 5:10 PM, Jaidev Deshpande wrote:
> Dear List,
>
> Suppose I have a function myfunc() in a module called mymodule.py
>
> As usual, I import this function in IPython with
>
> In[1]: from mymodule import myfunc
>
> Now if I find that there is something wrong with myfunc, I can open
> mymodule.py with a suitable editor and make the required changes.
>
> Now when I delete the original function and import the changed one,
>
> In[2]: del myfunc
>
> In[3]: from mymodule import myfunc
>
> it doesn't work as per the new changes. I have to close IPython and
> start all over again.
>
> Is there a less cumbersome way to do this, preferably without closing IPython?
in "normal" python:

import sys
reload(sys.modules['mymodule '])
from mymodule import myfunc

-- 
Bob Gailer
919-636-4239
Chapel Hill NC



More information about the Tutor mailing list