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
精彩评论