I have a Python module I'm developing that's includes a big JSON file as part of the data it relies on. I want Python users to be able to import the JSON file as a Python variable and for users of other programming languages, to be able to use the JSON file directly.
So, what I'm trying to figure out is what's the best way to make the JSON object "importable". Right now, my solution is in __init__.py:
import json
import os
with open(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'seals.json')) as f:
seals_data = json.load(f)
Then Python devs can call:
from my_module import seals_data
And it more or less works, but this feels weird to me, and I want to make sure there isn't a cleaner way to make the json importable.
loadit.seals_data). also, if no one imports the module, the file never gets parsed. thus,seals_datais a singleton.