尝试写入csv文件一小时。输出问题:每个字符后面都有一个逗号。我不确定为什么会发生这种情况,因为我之前已多次这样做了
id_list = []
with open(outfile1, 'r') as f:
reader = csv.reader(x.replace('\0','') for x in f)
for row in reader:
temp = row
try:
id = temp[3]
id_list.append(id)
except (IndexError, csv.Error, KeyError) as e:
pass
with open(results1, 'w') as f:
writer = csv.writer(f)
for id in id_list:
try:
prov_data = getData()
if prov_data is None:
continue
fab = prov_data['results'][0]['fab']
man = prov_data['results'][0]['man']
serv_type = prov_data['results'][0]['serv']
writer.writerows([str(id), str(fab), str(man), str(serv_type)])
except (IndexError, KeyError,csv.Error) as e:
pass