Load
load function
Load variables from a JSON file.
Parameters
config_file
(str): The file to load the variables from.unpack
(bool, optional): IfTrue
, the variables in the JSON file will be unpacked and returned as individual variables. IfFalse
, the entire contents of the JSON file will be returned as a dictionary. Defaults toFalse
.default
(Any, optional): The value to return if the file does not exist or is not a valid JSON file. Defaults toNone
.
Returns
Any
: The variables stored in the JSON file, either as a dictionary or as individual variables, depending on the value ofunpack
. Returnsdefault
if the file does not exist or is not a valid JSON file.
Raises
IOError
: If there is an error reading from the file.ValueError
: Ifunpack
isTrue
and the JSON file does not contain a dictionary.
Example
Last updated