import json
f=open("C:/Users/Lenovo/Desktop/数据/testmin.txt",encoding='utf-8')
line = f.readline().strip() #读取第一行
b=bytes(line,'unicode_escape').decode('utf-8')
txt=[]
txt.append(b)
dic={}
keys=[]
while line: # 直到读取完文件
c=b
line = f.readline().strip() # 读取一行文件,包括换行符
b=bytes(line,'unicode_escape').decode('utf-8')
#txt.append(b)
dic[c]=b
keys.append(c)
list1=[]
for key,value in dic.items():
#print('key:',key,'value:',value)
str1=key
str2=value
list2=[]
list2.append(str1)
list2.append(str2)
list1.append(list2)
print(list1)
f.close() # 关闭文件
json_data=json.dumps(dic)
#print(json_data)
with open('C:/Users/Lenovo/Desktop/数据/json_test.json', 'w') as f: # ‘w’表示写入文件,文件不存在则创建,存在则覆盖
json.dump(list1, f)
print("载入文件完成...")
f.close()
针对NLPTransformer模型古文现代文数据集格式进行更改
于 2023-11-21 08:15:59 首次发布