0

我有下面的代码片段我想添加错误检查喜欢

"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
4

1 回答 1

1

isRecordValid方法中添加一些东西怎么样?在不知道其余部分的情况下,您可以简单地添加以下内容:

def isRecordValid(s, p, v, time):
    if p > 10000:
        return False
    ... 
    # rest of existing method
于 2011-07-24T22:35:41.513 回答