From 414fd55cf202e7d9f488a6f1e137312600ddc01e Mon Sep 17 00:00:00 2001 From: Alice BRENON <alice.brenon@ens-lyon.fr> Date: Tue, 16 Jul 2024 18:31:23 +0200 Subject: [PATCH] Add a module exposing two functions to ease JSON load/saving by removing the need for a with: construct --- GEODE/Store/JSON.py | 9 +++++++++ GEODE/Store/__init__.py | 1 + 2 files changed, 10 insertions(+) create mode 100644 GEODE/Store/JSON.py diff --git a/GEODE/Store/JSON.py b/GEODE/Store/JSON.py new file mode 100644 index 0000000..df71be8 --- /dev/null +++ b/GEODE/Store/JSON.py @@ -0,0 +1,9 @@ +import json + +def load(inputJSON): + with open(inputJSON, 'r') as inputFile: + return json.load(inputFile) + +def save(value, outputJSON): + with open(outputJSON, 'w') as outputFile: + json.dump(value, outputFile, separators=(',', ':')) diff --git a/GEODE/Store/__init__.py b/GEODE/Store/__init__.py index 5af23d3..d753518 100644 --- a/GEODE/Store/__init__.py +++ b/GEODE/Store/__init__.py @@ -1,4 +1,5 @@ from GEODE.Store.Corpus import corpus, Directory, SelfContained +import GEODE.Store.JSON as JSON from GEODE.Store.Tabular import tabular, toTSV import os import os.path -- GitLab