[英]Python error checking
我下面有代码片段,我想添加错误检查
"If p > 10000 dont append list with record,
我该怎么做?
for line in idata.split("\r\n"):
if line == '':
continue
s, p, v, time = line.split(',')
try:
if isRecordValid(s,p,v,time):
s = s[1:-1]
p = (float(p))
v = int(v)
time = time[1:-1]
scol.append((s, p, v, time)) #moved this
except Exception as e: pass # print "log and error here, using " , stock
在isRecordValid
方法中添加isRecordValid
怎么办? 在不知道其余部分是什么样的情况下,可以简单地将其添加为开始:
def isRecordValid(s, p, v, time):
if p > 10000:
return False
...
# rest of existing method
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.