我有一个JSON文件,我必须将字符串[1]的每个实例都更改为\u e。你知道吗
#!/usr/bin/env python3
import fileinput
with fileinput.FileInput('reactions.json', inplace=True, backup='.bak') as file:
for line in file:
print(line.replace('[0]', '_c'), end='')
print(line.replace('[1]', '_e'), end='')
with open('reactions.json') as data_file:
data_reactions = json.load(data_file)
这就像一个魅力,但一旦我重命名文件扩展名为txt,该文件就不能再保存为JSON并正确读取。有没有办法改回来?我注意到将其保存为txt文件似乎会删除ENTER分隔符。。。我想。你知道吗
目前没有回答
相关问题 更多 >
编程相关推荐