Save
save function
Save variables or a dictionary to a JSON file.
Parameters
config_file
(str): The file to save the data to.**kwargs
(Any): The data to save. If a dictionary is passed as the only argument, it will be saved to the JSON file as is. If multiple keyword arguments are passed, they will be combined into a dictionary and saved to the JSON file.
Raises
FileNotFoundError
: If the directory forconfig_file
does not exist.PermissionError
: If the file cannot be opened for writing due to insufficient permissions.IOError
: If there is an error writing to the file.
Example
import pysettings_manager as pysm
# Save a dictionary to a JSON file
settings = {"foo": 1, "bar": "hello"}
pysm.save("settings.json", **settings)
# Save variables to a JSON file
foo = 1
bar = "hello"
pysm.save("settings.json", foo=foo, bar=bar)
# Save and merge multiple dictionaries to a JSON file
settings1 = {"foo": 1, "bar": "hello"}
settings2 = {"baz": 2, "qux": "world"}
pysm.save("settings.json", **settings1, **settings2)
Last updated