Skip to content

return tqdm instance in loop #1157

Answered by casperdcl
doraeric asked this question in Q&A
Discussion options

You must be logged in to vote

I can see the appeal of less indentation but the suggestion is very bad in terms of performance/speed.

If you don't mind swapping indentation for 2 extra lines, try this:

pbar = tqdm(range(3))
for i in pbar:
    time.sleep(.5)
    pbar.set_postfix_str(f'i ** 2: {i ** 2}')
pbar.close()

Replies: 2 comments

Comment options

casperdcl
Apr 1, 2021
Maintainer Sponsor

You must be logged in to vote
0 replies
Answer selected by casperdcl
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #1153 on April 05, 2021 14:37.