2 @package dmrg_json_utils 3 @brief Python module for reading JSON data files produced by a DMRG.x application. 5 @defgroup JSONUtilities JSON Utilities 6 @brief Python module for reading JSON data files produced by a DMRG.x application. 14 from shutil
import copyfile
17 """ Loads data from a JSON file and corrects unfinished runs by appending a 21 path: path to json file 22 appendStr: string to append in case of a JSONDecodeError 23 count: number of times this function was called recursively 26 dict object representing the loaded data 29 Exception: Unable to correctly load the file with the appended string. 32 For portability, this function detects a ValueError instead of a 33 JSONDecodeError which inherits from it. 36 filemod = path[:-5]+
"-mod"+
".json" 39 data = json.load(open(path))
41 data = json.load(open(filemod))
43 raise Exception(
'LoadJSONFile was not able to correct the file "{}" with an appended "{}". ' 44 'Check the file manually.'.format(path,appendStr))
47 copyfile(path,filemod)
48 fh = open(filemod,
"a")
54 """ Loads data from a JSON file containing dict entries and corrects unfinished 55 runs by appending "}". 58 path: path to json file 64 """Loads data from a JSON file with keys "headers" and "table", and corrects 65 unfinished runs by appending "]}". 68 path: path to json file 73 """Loads data from a JSON file represented as an array of dictionary entries 74 and corrects unfinished runs by appending "]". 77 path: path to json file def LoadJSONTable(path)
Loads data from a JSON file with keys "headers" and "table", and corrects unfinished runs by appendin...
def LoadJSONFile(path, appendStr, count=0)
Loads data from a JSON file and corrects unfinished runs by appending a string to the file...
def LoadJSONArray(path)
Loads data from a JSON file represented as an array of dictionary entries and corrects unfinished run...
def LoadJSONDict(path)
Loads data from a JSON file containing dict entries and corrects unfinished runs by appending "}"...