import json
with open('03092021-20-44-17.json', 'r') as object_1:
data = json.load(object_1)
c=0
for obj in data:
c=c+1
def split_in_files(data, amount):
step = len(data) // amount
pos = 0
for i in range(amount - 1):
res=data[pos:pos+step]
with open('output_file{}.json'.format(i+1), 'w') as file:
json.dump(res[0],file)
pos += step
# last one
res=data[pos:]
with open('output_file{}.json'.format(amount), 'w') as file:
json.dump(res[0], file)
split_in_files(data, c)
It's not so much the actual behavior, it's that doing this in the most straightforward and obvious way would take 5 lines, and so much of the extraneous code indicates a total lack of understanding (step will always be 1, the special treatment for the final element can just be removed, they seem to think data is a string starting about halfway through)
4
u/morganasreddit Sep 28 '21
Image Transcription: Code
I'm a human volunteer content transcriber for Reddit and you could be too! If you'd like more information on what we do and why we do it, click here!
1
u/inre_dan Sep 28 '21
considering the fact that the name is hardcoded this was probably a quick and dirty fix to something or other
1
u/[deleted] Sep 29 '21
Off to a great start why wouldnt we load the massive json file into memory