Found the solution to this a bit later (note that it does not work in pycharm jupyter, but only in the browser implementation). For me print
works fine, but here display
is advised, but it prints apostrophes around strings.
from time import sleep
from IPython.display import clear_output, display
for f in range(10):
clear_output(wait=True)
print(f) # use display(f) if you encounter performance issues
sleep(10)
Edit: Just wanted to add that TQDM is often also a good tool for this goal. It displays progress bars and allows you to write output below it or differ the description of each bar. See also this post.
import sys
from tqdm import tqdm
from time import sleep
values = range(3)
with tqdm(total=len(values), file=sys.stdout) as pbar:
for i in values:
pbar.set_description('processed: %d' % (1 + i))
pbar.update(1)
sleep(1)
And the notebook one with nice colours
from tqdm import tqdm, tqdm_notebook
from time import sleep
for i in tqdm_notebook(range(2), desc='1st loop'):
sleep(0.01)
tqdm.write(f"Done task {i}")
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…