sinat_30358031
佐仓大法好
2017-07-18 07:23
采纳率: 50%
浏览 7.3k

python怎么读取大概1400MB的大json文件

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.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

4条回答 默认 最新

  • TnTzzr
    TnTzzr 2017-07-18 07:31
    已采纳

    读取的时候把GC关掉。采纳啊。

    点赞 评论
  • oyljerry
    oyljerry 2017-07-18 08:10

    估计你机器内存不够了,用生成器,一行行读取

     for line in open(path):
           yield line.strip()
    
    点赞 评论
  • u011012932
    一去丶二三里 2017-07-20 02:06

    这才是 Pythonci 最完美的方式,既高效又快速:

     with open('filename', 'r', encoding = 'utf-8') as f:
        for line in f:
            do_something(line)
    
    点赞 评论
  • cg9001cg
    EdgarMoveOn 2017-07-20 03:54

相关推荐