aF. aF. - 1 year ago 266
Python Question

How to fix this python error? OverflowError: cannot convert float infinity to integer

it gives me this error:

Traceback (most recent call last):
File "C:\Users\Public\SoundLog\Code\Código Python\SoundLog\Plugins\", line 113, in onPaint
dc.DrawLine(valueWI, valueHI, valueWF, valueHF)
File "C:\Python26\lib\site-packages\wx-2.8-msw-unicode\wx\", line 3177, in DrawLine
return _gdi_.DC_DrawLine(*args, **kwargs)
OverflowError: cannot convert float infinity to integer

How can I avoid this to happen?

Answer Source

One of the four values valueWI, valueHI, valueWF, valueHF is set to float infinity. Just truncate it to something reasonable, e.g., for a general and totally local solution, change your DrawLine call to:

ALOT = 1e6
vals = [max(min(x, ALOT), -ALOT) for x in (valueWI, valueHI, valueWF, valueHF)]

best, of course, would be to understand which of the values is infinity, and why -- and fix that. But, this preferable course is very application-dependent, and entirely depends on the code leading to the computation of those values, which you give us absolutely no clue about, so it's hard for us to offer very specific help about this preferable option!-)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download