开发者

Error checking in python

After struggling with data download with ill tempered CSV fields. How could use try/Except format.

LL = [(XXX,YYY,ZZZ),] or [[XXX,YYY,ZZZ],] 

if above, how do i do below?

try: 
   IF XXX or YYY or ZZZ or AAA == 'N/A',
   (dont process data...skip to except and pass)
except:
   pass 

staeted here: Remove/Replace Erro开发者_JAVA技巧r from Tuple in python


Note that it's generally a bad idea to do a plain except:, as it will swallow exceptions that you need to know about.

LL = [("bad line",456,"N/A"),["good line", 123, 456],]

for line in LL:
    try: 
        if "N/A" in line:
            raise ValueError

        print line[0]

    except ValueError:
        print "skipped"


UPDATED

I suppose like that

try: 
   if "N/A" in [XXX,YYY,ZZZ,AAA]
       raise Exception()
except:
   pass 


for data in LL:
   try:
      if "N/A" in data:
         continue
      else:
         x, y, z = data
         # Process data...
   except Exception:
      continue
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜