# -*- coding: utf-8 -*- import os import json import sys reload(sys) sys.setdefaultencoding('utf-8') filelist=os.listdir('E:\log\files\') for item in filelist: print item newfile=open('E:\log\files2\target.txt','w') os.chdir('E:\log\files') for item in filelist: txt = open(item) json_txt=json.load(txt) tmp_str=','.join(map(lambda x:str(x),[json_txt['id'],json_txt['imageUrl'],json_txt['content']])) newfile.write(tmp_str) newfile.close()
注:源文件必须是无bom utf8格式