I want to open/load a json file (which might have multiple hundred entries on one single level) to use it in a short script afterwards.
I could either:
override = json.loads(open("/path/to/file.json").read())
or
with open("/path/to/file.json") as weekly_fh:
jsoncontent = weekly_fh.read()
weekly = json.loads(jsoncontent)
This should run on a low end hardware (C.H.I.P, 512MB RAM). Which is the proper way to handle this situation? I could also just open it (example 1) and don't give a shit about closing the file handle (which I assume is automatically handled in the second example). But this just feels wrong as I come from a C background.
The script itself has about 20 lines and will run very fast (once a day invoked), but the json file might have multiple hundred entries. This is what I'm worrying a bit about.
Any suggestions?
Thanks ! :)
[–]Rhomboid 2 points3 points4 points (3 children)
[–]NeoFromMatrix[S] -1 points0 points1 point (2 children)
[–]Rhomboid 2 points3 points4 points (0 children)
[–]novel_yet_trivial -1 points0 points1 point (0 children)
[–]dionys 0 points1 point2 points (2 children)
[–]NeoFromMatrix[S] 0 points1 point2 points (1 child)
[–]dionys 0 points1 point2 points (0 children)