我有一个简单的循环,它卡在除以零错误上。我正在运行一个 bool 来过滤掉零值分母,但由于某种原因,我使用的 bool 不起作用。有人可以帮忙吗?我正在使用 python 2.6.5
这是我的代码中的一个示例:
for i in range(0,len(lines)):
line = lines[i]
line = line.split(";")
leansz = line[9]
FW = line[34]
FS = line[35]
print "FS: %s %s"%(FS,type(FS)) #troubleshooting the denominator and its type
if FS == "0": #I have tried FS == 0 and FS == "0" to no avail
print 'FS == "0"' #checking if bool is working
continue #return to top of loop if denominator is zero
LnSzRa = float(leansz)/(float(FS)/2) #division by zero error
这是返回的示例,然后是错误:
FS: 184
<type 'str'>
FS: 1241
<type 'str'>
FS: 2763
<type 'str'>
FS: 1073
<type 'str'>
FS: 971
<type 'str'>
FS: 0
<type 'str'>
Traceback (most recent call last):
File "mpreader.py", line 50, in <module>
LnSzRa = float(leansz)/(float(FS)/2)
ZeroDivisionError: float division