I have run into some odd behavior.
I am trying to look up values in a dictionary, with the keys stored in a list. Each time I try this on the pyboard it fails, but the exact same sequence on micropython on linux works.
I have the following:
p.header = a list of strings, keys to the dictionary
rd a dictionary
look at this:
Code: Select all
>>> rd
{'HorizontalSelector': 0, 'VerticalSelector': 0, 'CTone': 5, 'ToneRange': 5, 'ATone': 5, 'TREM': 0, 'VIB': 0, 'S': '(|(+AB)(+CD))', 'BVol': 5, 'AUX0': 0, 'AUX1': 0, 'AVol': 5, 'CVol': 5, 'BTone': 5, 'MasterVol': 5, 'DTone': 5, 'DVol': 5, 'MasterTone': 5, 'Name': '(0,0)'}
>>> p.header
['HorizontalSelector', 'VerticalSelector', 'Name', 'MasterVol', 'MasterTone', 'AVol', 'ATone', 'BVol', 'BTone', 'CVol', 'CTone', 'DVol', 'DTone', 'ToneRange', 'S', 'TREM', 'VIB', 'AUX0', 'AUX1']
>>> rd.keys()
dict_keys(['HorizontalSelector', 'VerticalSelector', 'CTone', 'ToneRange', 'ATone', 'TREM', 'VIB', 'S', 'BVol', 'AUX0', 'AUX1', 'AVol', 'CVol', 'BTone', 'MasterVol', 'DTone', 'DVol', 'MasterTone', 'Name'])
>>> list(rd.keys())[0]
'HorizontalSelector'
>>> rd[list(rd.keys())[0]]
0 ### this is correct
>>> list(rd.keys())[0] == p.header[0]
True ### so the value at p.header[0] is the same as list(rd.keys())[0]
>>> rd[p.header[0]]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
KeyError: <value> ### How can this be explained!??
>>>
I am using the micropython firmware built locally (no changes to the makefile) from the github micropython repo...