-
Notifications
You must be signed in to change notification settings - Fork 0
load
sryu1 edited this page Jan 3, 2023
·
1 revision
Load variables from a JSON file.
-
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.
-
Any: The variables stored in the JSON file, either as a dictionary or as individual variables, depending on the value ofunpack. Returnsdefaultif the file does not exist or is not a valid JSON file.
-
IOError: If there is an error reading from the file. -
ValueError: IfunpackisTrueand the JSON file does not contain a dictionary.
# Unpack variables
foo, bar = load("settings.json", unpack=True)
# Return dictionary
settings = load("settings.json")