Quantcast

carriage return in ipython notebook?

classic Classic list List threaded Threaded
5 messages Options
mqk
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

carriage return in ipython notebook?

mqk
Hi

The carriage return character '\r' doesn't seem to work for me in an ipython notebook (0.12 or 0.13.dev). I'm on linux (xubuntu 12.04).

In an ipython shell:
In [1]: print 'Hello\rWorld'
World

In an ipython notebook:
In [1]: print 'Hello\rWorld'
Hello
World

Is this is a bug in the ipython notebook or behavior as expected?

The background to this question is that I'm trying to get this progressbar code to work properly in an ipython notebook. Currently the progressbar is not displayed properly, because (I suspect) the '\r' character isn't being honored.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: carriage return in ipython notebook?

MinRK
Correct, the notebook does not respect '\r' character, as it is not a terminal emulator.  You can clear the output in the IPython notebook with:

from IPython.core.display import clear_output
clear_output()

See here for a working progress bar in the notebook.

-MinRK

On Mon, Apr 9, 2012 at 14:27, mqk <[hidden email]> wrote:
Hi

The carriage return character '\r' doesn't seem to work for me in an ipython
notebook (0.12 or 0.13.dev). I'm on linux (xubuntu 12.04).

In an ipython shell:
In [1]: print 'Hello\rWorld'
World

In an ipython notebook:
In [1]: print 'Hello\rWorld'
Hello
World

Is this is a bug in the ipython notebook or behavior as expected?

The background to this question is that I'm trying to get
http://code.google.com/p/python-progressbar/ this progressbar code  to work
properly in an ipython notebook. Currently the progressbar is not displayed
properly, because (I suspect) the '\r' character isn't being honored.

--
View this message in context: http://python.6.n6.nabble.com/carriage-return-in-ipython-notebook-tp4717456p4717456.html
Sent from the IPython - User mailing list archive at Nabble.com.
_______________________________________________
IPython-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/ipython-user


_______________________________________________
IPython-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/ipython-user
mqk
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: carriage return in ipython notebook?

mqk
Hi MinRK

Thanks for your response. I did come across your working example, but I don't like it. :) The repeated clearing of the output results in a strobe-like appearance for me, and of course it also erases any previous output that is unrelated to the progress bar. Oh well.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: carriage return in ipython notebook?

MinRK


On Mon, Apr 9, 2012 at 14:46, mqk <[hidden email]> wrote:
Hi MinRK

Thanks for your response. I did come across your working example, but I
don't like it. :) The repeated clearing of the output results in a
strobe-like appearance for me, and of course it also erases any previous
output that is unrelated to the progress bar. Oh well.

The strobe complaint is common, and actually fixed in an outstanding PR.  You can selectively clear stdout/stderr/pyout, but not subsets of each of those.  That said, if you want the notebook to be a terminal emulator, you don't actually want the notebook.  For instance, a more natural progress bar for the notebook would just be written in Javascript.

Here's one I just wrote based on a quick Googling of 'javascript progress bar' since receiving your email:

import uuid
from IPython.core.display import HTML, Javascript, display

divid = str(uuid.uuid4())

display(HTML(
"""
<div style="border: 1px solid black; width:500px">
  <div id="%s" style="background-color:blue; width:0%%">&nbsp;</div>
</div> 
""" % divid)
)

for i in range(1,101):
    time.sleep(0.1)
    display(Javascript("$('div#%s').width('%i%%')" % (divid, i)))

It does require using my `clear_output` branch, pending as PR #1563, to avoid some ugliness.

-MinRK
 

--
View this message in context: http://python.6.n6.nabble.com/carriage-return-in-ipython-notebook-tp4717456p4717493.html
Sent from the IPython - User mailing list archive at Nabble.com.
_______________________________________________
IPython-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/ipython-user


_______________________________________________
IPython-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/ipython-user
mqk
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: carriage return in ipython notebook?

mqk
Cool, thanks for sharing that javascript progressbar implementation. Works for me.

Much appreciated.
Loading...