代码改变世界

python try except 异常忽略写法

2019-11-18 14:59  xplorerthik  阅读(1671)  评论(0编辑  收藏  举报

 

 

inputpath = 'postnew_00000' + str(i) + '_0'
fin = open(inputpath,'r')
reader = codecs.getreader('utf-8')(fin)

foutpth ='./data/'+ 'data_00000' + str(i) + '_0'
fout = open(foutpth, 'w')
writer = codecs.getwriter('utf-8')(fout)

data = reader.readline()
i = 0
while data:
i= i+1
try:
line = data.strip().split('\t')
query = line[0]
idSet = line[1].strip().split(',')
for articleId in idSet:
row = query + '\t' + articleId +'\n'
writer.write(row)
except:
pass
data = reader.readline()