--- title: Title keywords: fastai sidebar: home_sidebar ---
{% raw %}
{% endraw %} {% raw %}
import numpy as np
import time
from tqdm.auto import tqdm
{% endraw %} {% raw %}
np.random.normal
{% endraw %} {% raw %}
bar = tqdm(range(5))
for i in bar:
    time.sleep(1)
    tqdm.write('a'*i)
    bar.set_description(f'loss={np.random.normal()/10:.4f}')
    bar.set_postfix(loss=f'after {i}')
    print(i)
0
a
1
aa
2
aaa
3
aaaa
4

{% endraw %} {% raw %}
# STACKOVERFLOW

import inspect
import tqdm
# store builtin print
old_print = print
def new_print(*args, **kwargs):
    # if tqdm.tqdm.write raises error, use builtin print
    try:
        tqdm.tqdm.write(*args, **kwargs)
    except:
        old_print(*args, ** kwargs)
# globaly replace print with new_print
inspect.builtins.print = new_print
{% endraw %}