progress icon indicating copy to clipboard operation
progress copied to clipboard

Include "bar.goto()" in examples

Open bendemott opened this issue 4 years ago • 1 comments

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

bendemott avatar Jan 13 '21 23:01 bendemott

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

MarkCBell avatar Apr 13 '21 10:04 MarkCBell