0

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
3
  • 2
    except Exception as e: pass (or ...: log error, then ignore it) - because walking on like nothing happened when you got run over by a car is totally a good idea. Either truly handle an exception or let it propagate (yes, up to crashing the whole app if you can't handle it at all). Commented Jul 24, 2011 at 22:34
  • +1 @delnan. Always a valid point. Commented Jul 24, 2011 at 22:36
  • Error code is allowed to fail elsewhere just not here. Commented Jul 24, 2011 at 22:56

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.