NiltonVolpato / python-progressbar

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

ProgressBar() does not work when iterating over lines in a file #63

Closed jwhite007 closed 5 years ago

jwhite007 commented 5 years ago

Python 3.7.0 progressbar 2.5

from progressbar import ProgressBar
pbar = ProgressBar()
with open(<some file>) as rf:
    for line in pbar(rf):
        <process line>

Fails with "ValueError: cannot convert float NaN to integer"

NiltonVolpato commented 5 years ago

It fails because it doesn't know how many lines are going to be read. If you know that somehow you can provide in the maxval argument, or set it to UnknownLength like in this example: https://github.com/niltonvolpato/python-progressbar/blob/3f63b2f974cbdea4484dfad38a5522d369450d01/examples.py#L216