[IPython-user] printing lots of stuff to the screen

Walter Dörwald walter@livinglogic...
Sat May 26 05:48:34 CDT 2007


Stefan van der Walt wrote:
> Hi Walter
> 
> On Fri, May 25, 2007 at 11:14:24AM +0200, Walter Dörwald wrote:
>>> icap("foo(100)")
>>>
>>> which yields a browsable
>>>
>>>  ibrowse #0: icap('foo(100)')
>>>   # |_                  |
>>>   0 |We have 1 results..|
>>>   1 |We have 2 results..|
>>>   2 |We have 3 results..|
>>>   3 |We have 4 results..|
>>>   4 |We have 5 results..|
>>>   5 |We have 6 results..|
>>>
>>> etc.
>>>
>>> This is just a proof of concept.  I don't know the internals of ipipe
>>> or ipython well, so there may be better ways to implement it.
>> This looks good to me.
>>
>> However it has the problem, that the code must run to completion before
>> any output happens.
> 
> Attached, a new version that passes any output generated onto stdout
> while running.

I like the result!

Three (small) problems:

* Running the icap command a second time doesn't show any output to the 
terminal while running.
* The example in the docstring uses ix() instead of icap().
* icap should be added to __all__, so it's available after
     from ipipe import *

> I noticed a strange anomaly, though.
> 
> If I do
> 
> from ipipe import icap
> icap('for i in range(10): print i')
> 
> the result differs from when it is preceded by
> 
> from ipipe import *
> ils

In what way does it differ?

> Does ibrowser change the state of the terminal in any way?

Well, it uses curses, but the state of the terminal should be reverted 
to the previous state, as it uses curses.wrapper()

Servus,
    Walter


More information about the IPython-user mailing list