Preferences

class wpilib.Preferences

Bases: pybind11_builtins.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 {@link NetworkTable} by creating a table called “Preferences” with all the key-value pairs.

containsKey(self: wpilib.Preferences, 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

getBoolean(self: wpilib.Preferences, 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

getDouble(self: wpilib.Preferences, 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

getFloat(self: wpilib.Preferences, 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 getInstance()wpilib.Preferences

Get the one and only {@link Preferences} object.

Returns

pointer to the {@link Preferences}

getInt(self: wpilib.Preferences, 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

getKeys(self: wpilib.Preferences) → List[str]

Returns a vector of all the keys.

Returns

a vector of the keys

getLong(self: wpilib.Preferences, 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

getString(self: wpilib.Preferences, 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

initBoolean(self: wpilib.Preferences, key: str, value: bool) → None

Puts the given boolean into the preferences table if it doesn’t already exist.

initDouble(self: wpilib.Preferences, key: str, value: float) → None

Puts the given double into the preferences table if it doesn’t already exist.

initFloat(self: wpilib.Preferences, key: str, value: float) → None

Puts the given float into the preferences table if it doesn’t already exist.

initInt(self: wpilib.Preferences, key: str, value: int) → None

Puts the given int into the preferences table if it doesn’t already exist.

initLong(self: wpilib.Preferences, key: str, value: int) → None

Puts the given long into the preferences table if it doesn’t already exist.

initString(self: wpilib.Preferences, key: str, value: str) → None

Puts the given string into the preferences table if it doesn’t already exist.

putBoolean(self: wpilib.Preferences, 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

putDouble(self: wpilib.Preferences, 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

putFloat(self: wpilib.Preferences, 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

putInt(self: wpilib.Preferences, 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

putLong(self: wpilib.Preferences, 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

putString(self: wpilib.Preferences, 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

remove(self: wpilib.Preferences, key: str) → None

Remove a preference.

Parameters

key – the key

removeAll(self: wpilib.Preferences) → None

Remove all preferences.