Python进度条ValueError:值超出范围(Python Progress Bar ValueError: Value out of range)

编程入门 行业动态 更新时间:2024-10-11 07:27:17
Python进度条ValueError:值超出范围(Python Progress Bar ValueError: Value out of range)

我的进度条达到100%,然后抛出错误

from progressbar import Percentage, ProgressBar,Bar,ETA pbar = ProgressBar(widgets=[Bar('=', '[', ']'), ' ', Percentage(), ' ', ETA()]).start() for i,row in enumerate(cursor): ''' do some work here ''' pbar.update(i)

这就是我得到的

Traceback (most recent call last):=========================] 100% ETA: 0:00:00 File "X:\src\dbtest\PymssqlCheck.py", line 27, in <module> fiddler.getRows(condetails, dbdetails, 'compliance', 'doctable', '*', '1000') File "X:\src\utilities\fiddler.py", line 45, in getRows pbar.update(i) File "X:\Anaconda2\lib\site-packages\progressbar\__init__.py", line 271, in update raise ValueError('Value out of range') ValueError: Value out of range

为什么它达到100%然后失败? 我在用

https://github.com/niltonvolpato/python-progressbar

我甚至试过了

i=0 for row in cursor: ''' do some work here ''' if i < numrows: pbar.update(i) i=i+1

但我仍然得到同样的错误

编辑

我试过Tomasz Jakub Rup回答

pbar = ProgressBar(widgets=[Bar('=', '[', ']'), ' ', Percentage(), ' ', ETA()]) for row in pbar(cursor): ''' do some work here '''

我明白了

File "X:\fiddler.py", line 41, in getRows for row in pbar(cursor): File "X:\Anaconda2\lib\site-packages\progressbar\__init__.py", line 180, in __next__ if self.start_time is None: self.start() File "X:\Anaconda2\lib\site-packages\progressbar\__init__.py", line 311, in start self.update(0) File "X:\Anaconda2\lib\site-packages\progressbar\__init__.py", line 283, in update self.fd.write(self._format_line() + '\r') File "X:\Anaconda2\lib\site-packages\progressbar\__init__.py", line 243, in _format_line widgets = ''.join(self._format_widgets()) File "X:\Anaconda2\lib\site-packages\progressbar\__init__.py", line 223, in _format_widgets widget = format_updatable(widget, self) File "X:\Anaconda2\lib\site-packages\progressbar\widgets.py", line 38, in format_updatable if hasattr(updatable, 'update'): return updatable.update(pbar) File "X:\Anaconda2\lib\site-packages\progressbar\widgets.py", line 184, in update return '%3d%%' % pbar.percentage() File "X:\Anaconda2\lib\site-packages\progressbar\__init__.py", line 208, in percentage return self.currval * 100.0 / self.maxval TypeError: unsupported operand type(s) for /: 'float' and 'classobj'

知道为什么吗?

My progress bar reaches 100% and then throws the error

from progressbar import Percentage, ProgressBar,Bar,ETA pbar = ProgressBar(widgets=[Bar('=', '[', ']'), ' ', Percentage(), ' ', ETA()]).start() for i,row in enumerate(cursor): ''' do some work here ''' pbar.update(i)

here is what i get

Traceback (most recent call last):=========================] 100% ETA: 0:00:00 File "X:\src\dbtest\PymssqlCheck.py", line 27, in <module> fiddler.getRows(condetails, dbdetails, 'compliance', 'doctable', '*', '1000') File "X:\src\utilities\fiddler.py", line 45, in getRows pbar.update(i) File "X:\Anaconda2\lib\site-packages\progressbar\__init__.py", line 271, in update raise ValueError('Value out of range') ValueError: Value out of range

why does it reach 100% and then fail? i am using

https://github.com/niltonvolpato/python-progressbar

i even tried

i=0 for row in cursor: ''' do some work here ''' if i < numrows: pbar.update(i) i=i+1

but i still get the same error

Edit

i tried Tomasz Jakub Rup answer

pbar = ProgressBar(widgets=[Bar('=', '[', ']'), ' ', Percentage(), ' ', ETA()]) for row in pbar(cursor): ''' do some work here '''

and i get

File "X:\fiddler.py", line 41, in getRows for row in pbar(cursor): File "X:\Anaconda2\lib\site-packages\progressbar\__init__.py", line 180, in __next__ if self.start_time is None: self.start() File "X:\Anaconda2\lib\site-packages\progressbar\__init__.py", line 311, in start self.update(0) File "X:\Anaconda2\lib\site-packages\progressbar\__init__.py", line 283, in update self.fd.write(self._format_line() + '\r') File "X:\Anaconda2\lib\site-packages\progressbar\__init__.py", line 243, in _format_line widgets = ''.join(self._format_widgets()) File "X:\Anaconda2\lib\site-packages\progressbar\__init__.py", line 223, in _format_widgets widget = format_updatable(widget, self) File "X:\Anaconda2\lib\site-packages\progressbar\widgets.py", line 38, in format_updatable if hasattr(updatable, 'update'): return updatable.update(pbar) File "X:\Anaconda2\lib\site-packages\progressbar\widgets.py", line 184, in update return '%3d%%' % pbar.percentage() File "X:\Anaconda2\lib\site-packages\progressbar\__init__.py", line 208, in percentage return self.currval * 100.0 / self.maxval TypeError: unsupported operand type(s) for /: 'float' and 'classobj'

any idea why?

最满意答案

因为进度条默认为100。 如果有N步,则应指定maxval=N

例如:

from progressbar import Percentage, ProgressBar,Bar,ETA N = 300 pbar = ProgressBar(widgets=[Bar('=', '[', ']'), ' ', Percentage(), ' ', ETA()], maxval=N).start() for i in range(N+1): pbar.update(i)

David and Tomasz, both of you guys came pretty close. the solution that worked is

pbar = ProgressBar(widgets=[Bar('>', '[', ']'), ' ', Percentage(), ' ', ETA()],maxval=someMaxValue) for row in pbar(cursor): ''' do some work '''

更多推荐

本文发布于:2023-07-30 16:19:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1338755.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:进度条   ValueError   Python   range   Bar

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!