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

Include "bar.goto()" in examples #91

Open
bendemott opened this issue Jan 13, 2021 · 1 comment
Open

Include "bar.goto()" in examples #91

bendemott opened this issue Jan 13, 2021 · 1 comment

Comments

@bendemott
Copy link

With the current documentation a common use case which is advancing to a specific amount.

In the case of downloading a file from sftp (for example) the callback tells how many bytes have been transferred and how many bytes total.
the next() method doesn't work in this case.

for this case bar.goto() seems to work well but there are no examples in the documentation

@MarkCBell
Copy link

bar.next() does take an optional argument n which defaults to 1 and specifies the amount to increment the bar's index by. See https://github.com/verigak/progress/blob/master/progress/__init__.py#L123.

So you can do something like:

data = b""
with progress.bar.Bar('Download', max=file_size) as bar:
    while True:
        packet = ftp.read()
        bar.next(len(packet))
        data += packet
        if not packet: break

# Do something with data

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

2 participants