Question

I have code snippet below I would like to add error checking Like

"If  p > 10000 dont append list with record, 

How would I do this?

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
Was it helpful?

Solution

What about adding something in the isRecordValid method? Without knowing what the rest of it looks like, you could simple add this to start:

def isRecordValid(s, p, v, time):
    if p > 10000:
        return False
    ... 
    # rest of existing method
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top