修改json格式的数据文件为txt格式

2021-01-16 17:12

阅读:628

标签:nes   path   数据   lan   bst   数据文件   odi   des   print   

import json
path = r"H:\weibo\4\sdc-907869a8-212f-11e8-9a3e-ab0426199701_77a6516b-4816-40cf-beaf-cc5d31f07e41" #:文件位置
file = open(path, ‘r‘, encoding=‘utf-8‘) #:打开文件
file1 = open(r"H:\ceshi\test4.txt", ‘a‘,encoding="utf-8") #:打开.text文件

for line in file.readlines(): #:按照列表方式读取文件
fileJson = json.loads(line) #:转义为字典
#:拿取值 key/values
key = fileJson["key"]
asp = fileJson["asp"]
ID = fileJson["id"]
nfc = fileJson["nfc"]
uau = fileJson["uau"]
ubi = fileJson["ubi"]
ubstat = fileJson["ubstat"]
ubu = fileJson["ubu"]
udes = fileJson["udes"]
ufc = fileJson["ufc"]
ufcn = fileJson["ufcn"]
ugen = fileJson["ugen"]
ugt = fileJson["ugt"]
uid = fileJson["uid"]
uim = fileJson["uim"]
uip = fileJson["uip"]
uit = fileJson["uit"]
uiu = fileJson["uiu"]
uiv = fileJson["uiv"]
ulan = fileJson["ulan"]
ulc = fileJson["ulc"]
uloc = fileJson["uloc"]
ulp = fileJson["ulp"]
umc = fileJson["umc"]
una = fileJson["una"]
unn = fileJson["unn"]
urem = fileJson["urem"]
upti = fileJson["upti"]
urn = fileJson["urn"]
urt = fileJson["urt"]
ust = fileJson["ust"]
uuo = fileJson["uuo"]
uut = fileJson["uut"]
uvi = fileJson["uvi"]
uvip = fileJson["uvip"]
file1.write(
str(key) + "," + str(asp) + "," + str(ID) + "," + str(nfc) + "," + str("uau") + "," + str(ubi) + "," + str(ubstat) + "," + str(ubu) + "" + str(udes) + "" + str(ufc) + "," + str(ufcn) + "," +
str(ugen) + "," + str(ugt) + "," + str(uid) + "," + str(uim) + "," + str(uip) + "," + str(uit) + "," + str(uiu) + "," + str(uiv) + "," + str(ulan) + "" + str(ulc) + "," + str(uloc) + "," +
str(ulp) + "," + str(umc) + "," + str(una) + "" + str(unn) + "," + str(upti) + "," + str(urem) + "" + str(urn) + "" + str(urt) + "," + str(ust) + "," + str(uuo) + "," + str(uut) + "," + str(uvi) + "" + str(uvip)
)
file1.write("\n")

print("导入完毕!")

修改json格式的数据文件为txt格式

标签:nes   path   数据   lan   bst   数据文件   odi   des   print   

原文地址:https://www.cnblogs.com/yandh/p/13375076.html


评论


亲,登录后才可以留言!