import codecs
content=''
with codecs.open('./xxx.json', 'r') as content_file:
for line in content_file.readlines():
content=content+line
records = json.loads(json.dumps(content))
jupyter 提示The kernel appears to have died. It will restart automatically.
读取的时候把GC关掉。采纳啊。
估计你机器内存不够了,用生成器,一行行读取
for line in open(path):
yield line.strip()
这才是 Pythonci 最完美的方式,既高效又快速:
with open('filename', 'r', encoding = 'utf-8') as f:
for line in f:
do_something(line)