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

tqdm.std: add update_to #1540

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions tqdm/cli.py
Expand Up @@ -288,7 +288,7 @@ def callback(i):
t.update(numeric(i.decode()))
else: # update_to
def callback(i):
t.update(numeric(i.decode()) - t.n)
t.update_to(numeric(i.decode()))
for i in stdin:
write(i)
callback(i)
Expand All @@ -304,7 +304,7 @@ def callback(i):
t.update(numeric(i.decode()))
elif update_to:
def callback(i):
t.update(numeric(i.decode()) - t.n)
t.update_to(numeric(i.decode()))
else:
callback = t.update
callback_len = True
Expand Down
5 changes: 5 additions & 0 deletions tqdm/std.py
Expand Up @@ -1263,6 +1263,11 @@ def update(self, n=1):
self.last_print_t = cur_t
return True

def update_to(self, n, total=None):
if total is not None:
self.total = total
self.update(n - self.n)

def close(self):
"""Cleanup and (if leave=False) close the progressbar."""
if self.disable:
Expand Down