SuggestionDict¶
- class bpod_core.misc.SuggestionDict ¶
-
A dictionary that suggests similar keys on failed lookup.
On
KeyError, raiseserror_classwith a message that includes the closest match from the existing keys viasuggest_similar(), making typos and near-misses easier to diagnose.- Parameters:
dictionary (
MutableMapping) – Initial key-value pairs.name (
str, default:'key') – Human-readable label for the key type used in the error message.error_class (
typeofException, default:KeyError) – Exception class to raise on failed lookup. Must accept a single string argument.
Examples
>>> d = SuggestionDict({'Port1': 1, 'Port2': 2}, name='channel') >>> d['Port1'] 1 >>> d['Prot1'] Traceback (most recent call last): ... KeyError: "No such channel: 'Prot1' - did you mean 'Port1'?"