Preferences
- class wpilib.Preferences
Bases:
pybind11_object
The preferences class provides a relatively simple way to save important values to the roboRIO to access the next time the roboRIO is booted.
This class loads and saves from a file inside the roboRIO. The user cannot access the file directly, but may modify values at specific fields which will then be automatically periodically saved to the file by the NetworkTable server.
This class is thread safe.
This will also interact with NetworkTable by creating a table called “Preferences” with all the key-value pairs.
- static containsKey(key: str) bool
Returns whether or not there is a key with the given name.
- Parameters:
key – the key
- Returns:
if there is a value at the given key
- static getBoolean(key: str, defaultValue: bool = False) bool
Returns the boolean at the given key. If this table does not have a value for that position, then the given defaultValue value will be returned.
- Parameters:
key – the key
defaultValue – the value to return if none exists in the table
- Returns:
either the value in the table, or the defaultValue
- static getDouble(key: str, defaultValue: float = 0.0) float
Returns the double at the given key. If this table does not have a value for that position, then the given defaultValue value will be returned.
- Parameters:
key – the key
defaultValue – the value to return if none exists in the table
- Returns:
either the value in the table, or the defaultValue
- static getFloat(key: str, defaultValue: float = 0.0) float
Returns the float at the given key. If this table does not have a value for that position, then the given defaultValue value will be returned.
- Parameters:
key – the key
defaultValue – the value to return if none exists in the table
- Returns:
either the value in the table, or the defaultValue
- static getInt(key: str, defaultValue: int = 0) int
Returns the int at the given key. If this table does not have a value for that position, then the given defaultValue value will be returned.
- Parameters:
key – the key
defaultValue – the value to return if none exists in the table
- Returns:
either the value in the table, or the defaultValue
- static getKeys() list[str]
Returns a vector of all the keys.
- Returns:
a vector of the keys
- static getLong(key: str, defaultValue: int = 0) int
Returns the long (int64_t) at the given key. If this table does not have a value for that position, then the given defaultValue value will be returned.
- Parameters:
key – the key
defaultValue – the value to return if none exists in the table
- Returns:
either the value in the table, or the defaultValue
- static getString(key: str, defaultValue: str = '') str
Returns the string at the given key. If this table does not have a value for that position, then the given defaultValue will be returned.
- Parameters:
key – the key
defaultValue – the value to return if none exists in the table
- Returns:
either the value in the table, or the defaultValue
- static initBoolean(key: str, value: bool) None
Puts the given boolean into the preferences table if it doesn’t already exist.
- static initDouble(key: str, value: float) None
Puts the given double into the preferences table if it doesn’t already exist.
- static initFloat(key: str, value: float) None
Puts the given float into the preferences table if it doesn’t already exist.
- static initInt(key: str, value: int) None
Puts the given int into the preferences table if it doesn’t already exist.
- static initLong(key: str, value: int) None
Puts the given long into the preferences table if it doesn’t already exist.
- static initString(key: str, value: str) None
Puts the given string into the preferences table if it doesn’t already exist.
- static remove(key: str) None
Remove a preference.
- Parameters:
key – the key
- static removeAll() None
Remove all preferences.
- static setBoolean(key: str, value: bool) None
Puts the given boolean into the preferences table.
The key may not have any whitespace nor an equals sign.
- Parameters:
key – the key
value – the value
- static setDouble(key: str, value: float) None
Puts the given double into the preferences table.
The key may not have any whitespace nor an equals sign.
- Parameters:
key – the key
value – the value
- static setFloat(key: str, value: float) None
Puts the given float into the preferences table.
The key may not have any whitespace nor an equals sign.
- Parameters:
key – the key
value – the value
- static setInt(key: str, value: int) None
Puts the given int into the preferences table.
The key may not have any whitespace nor an equals sign.
- Parameters:
key – the key
value – the value
- static setLong(key: str, value: int) None
Puts the given long (int64_t) into the preferences table.
The key may not have any whitespace nor an equals sign.
- Parameters:
key – the key
value – the value
- static setString(key: str, value: str) None
Puts the given string into the preferences table.
The value may not have quotation marks, nor may the key have any whitespace nor an equals sign.
- Parameters:
key – the key
value – the value