[IPython-dev] Re: [IPython-user] New feature in CVS, testers?

Fernando Perez Fernando.Perez at colorado.edu
Sat Mar 19 20:06:00 EST 2005

Ville Vainio wrote:

> Of course it's called 'subprocess'
> http://docs.python.org/lib/module-subprocess.html
> It's also available for older Python versions as separate download I
> think.
> It might work to create a subprocess.Popen, inheriting stdin from the
> current process and capturing stdout and stderr to file-like objects
> that both print the output and store it in strings for future
> processing.

OK, I admit defeat and retreat.  I tried quite hard to get this to work across 
all cases using subprocess (it runs fine on 2.3), but couldn't.

I am therefore forced to back off the autocapture for shell commands, I'm 
afraid.  If you or anyone can figure out how to make this work reliably, 
addressing the various points you mentioned earlier (non-blocking stdin/out), 
I'd love to see a solution and will gladly incorporate it.  But after spending 
a fair amount of effort and failing to find a solid solution, I have to move on.

Some good came out of this, though: the %sc/%sx magics now capture to these 
special objects with the .l/.s/.n attributes which make their interactive use 
a lot easier.  So not all is lost:

In [6]: sc a=ls s*py

In [7]: a
Out[7]: 'sanner.py\nscopes.py\nsplot.py\nstrings.py'

In [8]: a.s
Out[8]: 'sanner.py scopes.py splot.py strings.py'

In [9]: a.l
Out[9]: ['sanner.py', 'scopes.py', 'splot.py', 'strings.py']

In fact, now that we have these, I have a question on which I'd like feedback. 
  I am very tempted to change the behavior of !! to capture to a string 
instead of a list.  This would make it a bit more uniform, since !!foo would 
just capture directly whatever !foo did, without any changes.  Using _.l would 
give you the list form if that's what you want, at any time.

I guess it's a question of which use is more common: the list form or the 
string form?  Capturing just to a list is also less expensive, since no 
additional processing is necessary, so I'm leaning strongly in that direction. 
This makes the capture very inexpensive, and the list form is only a .l away 
for those who need it, and they pay for it only when needed (instead of doing 
so on every capture).

So unless I hear a good counter argument, I'll switch !!foo over to plain 
string capture into one of these new objects.

And many thanks for the feedback and testing on this.



More information about the IPython-dev mailing list