[IPython-User] Refactoring in ipynb

Junkshops junkshops@gmail....
Sat Jul 14 13:44:29 CDT 2012


Hey Aaron,

Thanks for the suggestions. Sorry if I wasn't clear in my OP - my 
question is more along the lines of how to refactor safely without 
restarting the kernel. Both the methods below would require that.

> The fact that the ipynb saves all your variables in memory is great, 
> but it makes refactoring a little more tricky since you have to 
> remember to delete your old function/variable names.
Here's where I think I should clarify - I mean deleting the 
function/variable names *from the kernel's memory.* Even if you delete 
the names from the notebook, they'll still exist in the kernel. Hence if 
you miss renaming a function call in the notebook somewhere, it'll still 
use the old function resident in the kernel's memory - even though the 
old function never appears in the notebook. That can make bugs tricky to 
track down unless you restart the kernel.

Cheers,

-g

On 7/14/2012 10:46 AM, Aaron Meurer wrote:
> If the variable name is a fairly unique one, you could do a find and 
> replace in the JSON itself using a text editor. I think there might 
> also be a way to export the notebook to a .py file and reimport it, in 
> which case you can use any Python refactoring tool under the sun 
> (others will have to say how to do this or correct me if I'm wrong here).
>
> Aaron Meurer
>
> On Jul 14, 2012, at 10:55 AM, "junkshops@gmail.com 
> <mailto:junkshops@gmail.com>" <junkshops@gmail.com 
> <mailto:junkshops@gmail.com>> wrote:
>
>> The fact that the ipynb saves all your variables in memory is great, 
>> but it makes refactoring a little more tricky since you have to 
>> remember to delete your old function/variable names. Otherwise, if 
>> you miss changing a name somewhere it can lead to hard to fix bugs 
>> since the old variable/function still exists but is invisible to the 
>> user.
>>
>> How do people deal with this other than being extremely careful when 
>> refactoring? I've taken to restarting the kernel after I make 
>> extensive changes to make sure I haven't forgotten to delete any 
>> variables, but I assume some of the more experienced users have 
>> better methods. I'd definitely be interested in suggestions.
>>
>> Cheers, Gavin
>>
>> _______________________________________________
>> IPython-User mailing list
>> IPython-User@scipy.org <mailto:IPython-User@scipy.org>
>> http://mail.scipy.org/mailman/listinfo/ipython-user
>
>
> _______________________________________________
> IPython-User mailing list
> IPython-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-user
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/ipython-user/attachments/20120714/ad71c60a/attachment.html 


More information about the IPython-User mailing list