读取json.bz2 fi时跳到特定行

2024-05-19 17:08:18 发布

您现在位置:Python中文网/ 问答频道 /正文

我目前正在通过wikidata json.bz2转储读取以下设置来提取数据:

f = bz2.BZ2File("latest-all.json.bz2", "r")
next(f)  # skip the first line
for line in f:
    json_set = json.loads(line[:-2])
    #etc...

因为这是一个漫长的过程,我希望能够停止和重新启动程序在一个给定的行索引,而不必重新阅读整个文件从一开始。有没有比仅仅使用next()和行计数器更好的方法呢


Tags: the数据injsonforlinealllatest