API Reference#
- class as_you_wish.Config#
The config class represents a set of options and values and can be used to load settings from files.
- __init__()#
Constructs a new Config
- define(key, default_value, comment='')#
Creates a new option
This is used to set a new k,v pair for an option. You can also chain these methods like so:
config.define('westley.actor', 'Cary Elwes').define('westley.ressurect_count', 1)
- Parameters:
key (str) – A unique identifier that refers to the value, used to retrieve the value in the get() method
default_value (Any) – The default value for this setting. Used to get the type that the option should be and it is used to create a setting in the options file when there isn’t one.
comment (str, optional) – A descriptive message to help users figure out what each setting does, defaults to ‘’
- Raises:
TypeError – If the key provided is a subsection of a previously set key, a type error will be raised
- Returns:
self
- Return type:
- get(key)#
Returns the value specificied by a key.
- Parameters:
key (str) – The lookup key (unique identifier)
- Returns:
The value associated with the key. Please remember which keys are associated with which data types.
- Return type:
Any
- load(filename)#
Attempts to load a configuration from a specified file.
This function will also create the file if it doesn’t exists already and it will update the file with any options that may not be defined.
- Parameters:
filename (str) – The filename to load the config from.
- save(filename)#
Saves the configuration to a specific file. Mostly used internally to fix broken configs, but can be used externally to allow users to update settings either through a file or another interface.
- Parameters:
filename (str) – The file to save the config to.
- class as_you_wish.ConfigValue#
Represents the value stored in a certain key. Keeps track of the type of the data, the data itself and the comment associated with the key. It also checks the data to make sure it fits the datatype.
- Parameters:
data_type (type) – The data type of data
data (Any) – The data stored by this ConfigValue
comment (str) – The documentation for this value
- __init__(data_type, data, comment)#
- Parameters:
comment (str) –