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. Returnsdefaultif the file does not exist or is not a valid JSON file.
Raises
IOError: If there is an error reading from the file.ValueError: IfunpackisTrueand the JSON file does not contain a dictionary.
Example
import pysettings_manager as pysm
# Unpack variables
foo, bar = pysm.load("settings.json", unpack=True)
# Return dictionary
settings = pysm.load("settings.json")Last updated