NiltonVolpato / python-progressbar

Text progress bar library for Python
Other
412 stars 105 forks source link

`with` #70

Open kousu opened 4 years ago

kousu commented 4 years ago

It would be cool if I could write:

        with ProgressBar(widgets=widgets, maxval=os.stat(fname).st_size) as pbar:
            fp = open(fname, 'rb')
            fp = ProgressFile(fp, pbar.update)
            client.uploadFile(dataset, fp, posixpath.join(dir, file))

With pbar.start() and pbar.finish() sequestered into pbar.__enter__ and pbar.__exit__ respectively.

NiltonVolpato commented 3 years ago

Yeah, that's a good idea. I like it. I think it's convenient

thorwhalen commented 3 years ago

I just pushed a pull request that does this.

thorwhalen commented 3 years ago

Here: https://github.com/niltonvolpato/python-progressbar/pull/78. If it's not merged, you can simply use the fork: https://github.com/thorwhalen/python-progressbar