Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: setting of info, without needing pbar object #1555

Open
4 of 6 tasks
sradc opened this issue Feb 27, 2024 · 0 comments
Open
4 of 6 tasks

Proposal: setting of info, without needing pbar object #1555

sradc opened this issue Feb 27, 2024 · 0 comments

Comments

@sradc
Copy link

sradc commented Feb 27, 2024

  • I have marked all applicable categories:
    • documentation request (i.e. "X is missing from the documentation." If instead I want to ask "how to use X?" I understand [StackOverflow#tqdm] is more appropriate)
    • new feature request
  • I have visited the [source website], and in particular
    read the [known issues]
  • I have searched through the [issue tracker] for duplicates
  • I have mentioned version numbers, operating system and
    environment, where applicable:
    import tqdm, sys
    print(tqdm.__version__, sys.version, sys.platform)

progress bar info can be set in two ways:

  1. With a context manager. This introduces extra indententation, and an extra line.
with tqdm(["a", "b", "c", "d"]) as pbar:
    for item in pbar:
        pbar.set_description(...)
        pbar.set_postfix(...)
  1. With a pbar variable. This introduces two extra lines.
pbar = tqdm(["a", "b", "c", "d"])
for item in pbar:
    pbar.set_description(...)
    pbar.set_postfix(...)
pbar.close()

The proposal here is for a third alternative, which would be:

for item in tqdm(["a", "b", "c", "d"]):
    tqdm.set_description(...)
    tqdm.set_postfix(...)

Where tqdm.set_description and tqdm.set_postfix set a value, and then the next pbar to update takes these values.

It is slightly magical, but reminds me a bit of of the matplotlib.pyplot stateful API versus the object oriented one; where the stateful api is often more convenient for quick simple things.

I think it would help to simplify and reduce clutter in loops.

Edit:

Ah, there's a third way:

for item in (pbar := tqdm(["a", "b", "c", "d"])):
    pbar.set_description(...)
    pbar.set_postfix(...)

Maybe this is preferable to the above proposal; although it is perhaps somewhat more complex looking, it's not so bad.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant