Each call to HTML()
just creates an object of class IPython.display.HTML
. Every object from this class, when displayed by IPython in a notebook, is shown as an html element that is included in the page. See
Custom Display for details.
IPython default behavior is to display the last object computed in a cell, if it wasn't used or assigned, which means that a cell with the following code works as intended:
from IPython.display import display,HTML,clear_output
HTML('<b>Hello world</b>')
What you want here is to instruct IPython to display all your objects in sequence, not just the last one created. The IPython.display.display()
function does the trick:
import sys
import time
from IPython.display import display,HTML,clear_output
for i in range(10):
time.sleep(1)
clear_output(wait=True)
display(HTML('<b> Hello ' + str(i) + '</b>'))