reload and work flow suggestions

Peter Cacioppi peter.cacioppi at gmail.com
Mon Sep 23 17:35:59 EDT 2013


On Saturday, September 21, 2013 2:43:13 PM UTC-7, Peter Cacioppi wrote:
> This is an idea brought over from another post.
> 
> 
> 
> When I write Python code I generally have 2 or 3 windows open simultaneously.
> 
> 
> 
> 1) An editor for the actual code.
> 
> 2) The interactive interpreter.
> 
> 3) An editor for the unit tests. (Sometimes skipped for quick one-off scripts)
> 
> 
> 
> My work flow tends to involve using 2 to debug the issues that come up with 1 and 3. I'll write some new code in 1, play around with it in 2, then solidify the tests in 3. Or a test in 3 fails and I dig around with it using 2.
> 
> 
> 
> My problem is that I tend to use reload() quite a bit. I want to call functions and construct objects that are inside the guts of 1 and pass them arguments that are stored as variables in 2. If I restart my session for 2 I lose these variables (iPython does mitigate the pain here somewhat). Hence, I reload() modules into 2 when they are changed.
> 
> 
> 
> I use ipdb a lot in 2. I usually don't feel comfortable with virgin code or a debug fix that hasn't been stepped through with the debugger.
> 
> 
> 
> Is there something wrong with this work flow? I understand most python experts avoid reload(). So what are they doing that I'm not? I love the ability of Python to quickly let you dive deep into your code and set up a difficult case with 2, it's hard to imagine giving this up, and it's hard to imagine using it without reload(). 
> 
> 
> 
> Thanks for any tips.

So when I say I exploit the intellisense of iPython, it's simply this.

I have a "working on X" script that has some handy variables and runs whatever is currently of interest in the functional code or the units tests. It even launches into the ipdb debugger, if needed. 

The "working on X" is kept in the scripts directory of iPython. The older "working on Y" scripts are renamed to "not working on Y", so that there is only one script in that particular directory that starts with "wo". 

When iPython launches, I just type run wo [tab] and it completes the file name. So the whole "proxy for reload" process is actually pretty quick. For me it's faster than what I used to do with reload(), plus the "working on" script keeps a nice record of where I was in a debugging/experiment process. iPython makes it easy to create history dumps which can then be selectively copied over to the "working on" if I forget what was useful.

At any rate, it sounds like emacs plays very well with python and iPython, not disparaging the utility of emacs kung fu.

But if you want to use a different editor (I use idle for editing), and also use iPython for interactivity (which is very slick), this workflow works nice for me and might be helpful to you. 

Cheers



More information about the Python-list mailing list