Допустимо два раза fn?
import json
EOL = '\n'
def convert_big_map2values_jsons(fn):
with open(fn) as f:
big_data = json.load(f)
idx = {}
p = 0
with open(fn + 's', 'w') as f:
for k, v in big_data.items():
idx[k] = p
line = json.dumps(v)
writed_size = f.write(line + EOL)
p += writed_size
with open(fn + '.index.json', 'w') as f:
json.dump(idx, f)
def load_by_index(index, filename: str):
with open(filename + '.index.json', 'r') as f:
idx = json.load(f)
offset = idx[str(index)]
with open(filename + 's', 'r') as f:
f.seek(offset)
return json.loads(f.readline())
if __name__ == '__main__':
fn = 'big_fucking_file.json'
fn = 'tmp/1.json'
convert_big_map2values_jsons(fn)
print('Loaded by index:', load_by_index(256, fn))
Если изменить bytes на buffer, то код работает без ошибок.
Мне необходимо будет сделать визуализацию треков по координатам для каждого эвента.