1. 程式人生 > >invalid literal for float(): 和 OverflowError: cannot convert float infinity to integer 問題

invalid literal for float(): 和 OverflowError: cannot convert float infinity to integer 問題

CRITICAL:報錯資訊為:Traceback (most recent call last):
 File "/opt/HDS_volume_expand.py", line 220, in vv_expand_check
   vv_size = type_conversion((vv_show_read_1[0]) * 1024)
 File "/opt/HDS_volume_expand.py", line 16, in type_conversion
   num = math.ceil(float(str))
ValueError: invalid literal for float(): 4.4634.4634.4634.4634.4634.4634.4634.4634.4634.4634.4634.*



CRITICAL:報錯資訊為:Traceback (most recent call last):
 File "/opt/HDS_volume_expand.py", line 291, in 
   vv_expand_check()
 File "/opt/HDS_volume_expand.py", line 229, in vv_expand_check
   if int(vv_size) >= type_conversion(prd_volume_expand):
OverflowError: cannot convert float infinity to integer

 

錯誤的原因來自於type_conversion((vv_show_read_1[0]) * 1024)  (vv_show_read_1[0])是一個字串,本意是先進行型別轉換,再進行*1024的計算,但因為括號忘記刪除的原因,導致了字串和數字相乘,產生了這2個錯誤, 前者是vv_show_read_1[0]轉換後是一個小數,後者vv_show_read_1[0]轉換後是這個整數。 這2個問題都可以歸咎到inf錯誤。