Load

load function

Load variables from a JSON file.

Parameters

  • config_file (str): The file to load the variables from.

  • unpack (bool, optional): If True, the variables in the JSON file will be unpacked and returned as individual variables. If False, the entire contents of the JSON file will be returned as a dictionary. Defaults to False.

  • default (Any, optional): The value to return if the file does not exist or is not a valid JSON file. Defaults to None.

Returns

  • Any: The variables stored in the JSON file, either as a dictionary or as individual variables, depending on the value of unpack. Returns default 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: If unpack is True and 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