前端之家收集整理的这篇文章主要介绍了
python解析json数据并导出成普通文本示例,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
感兴趣python解析json数据并导出成普通文本示例的小伙伴,下面一起跟随编程之家 jb51.cc的小编来看看吧。
# 来自jb51.cc
# -*- encoding:utf-8 -*-
import json
import warnings
warnings.filterwarnings("ignore")
if __name__=="__main__":
import sys
reload(sys)
sys.setdefaultencoding( "utf-8" )
if len(sys.argv)==1:
print "need argv"
else:
print sys.argv
for json_array in open('/home/spark/opt/Log_Data/Py_logproc/log_tmpdir/yemaopythonlog'):
yemao_array = json.loads(json_array)
for yemao in yemao_array:
if not yemao.has_key('_reason'):
time = yemao['time']
url_current = yemao['url_current']
phone = yemao['phone']
token = yemao['token']
f=open('/home/spark/opt/Log_Data/Py_logproc/log_tmpdir/xxxx.txt','a+')
f.write('%d'%time+'|'+url_current+'|'+phone+'|'+token+'\n')
f.close()
print 'yemao_array_insert_file done'