import re file1 = '/Users/jian.wang13/code/huisu/0808/luce.txt' file2 = '/Users/jian.wang13/code/huisu/0808/luce_sql.txt' f2 = open(file2,'w') with open(file1,'r') as f1: for i in f1: i1 = re.split('n',i) i2 = "','".join(i1) #i3 = i2.strip() #print(i2) f2.write(i2)
#################################
python变量引用可以整合为为字符串拼接
例如
where = "task_id='XXXXX_YYYYY'"
替换成
ts_id = "'"+i.strip()+"'" where = "task_id="+ts_id
两者最终的print出来的是一样的