I have a simple piece of code that is throwing me for a loop,
CONTROLLER_CONFIG = {
'ID': 1986,
'CE': 1,
'NI': 'Controller',
'AP': 4
}
def configure_node(**kwargs):
for cmd, value in kwargs.items():
print(cmd, ' ', value)
>>configure_node(**CONTROLLER_CONFIG)
When I run this i get a "KeyError: N". I can run this on my computer fine, but when I try to run in it through the micropython terminal from my xbee dev board it throws the error. I can also just run the For loop in the terminal with the same dictionary no problem.
KeyError that I don't Understand
Re: KeyError that I don't Understand
On current github version of MicroPython this works fine.
It also works on the (very old!) version of MicroPython running on the online simulator at http://micropython.org/unicorn/ so I'm don't think that this is a bug that's been fixed since Digi's version was forked?
I don't know much about MicroPython-on-xbee. As far as I know Digi haven't ever released source code for it? I wonder if maybe there's some feature they're disabling that's changing the behaviour of kwargs?
Maybe can you try running:
Code: Select all
MicroPython v1.12-618-gfeed2a046 on 2020-07-03; linux version
Use Ctrl-D to exit, Ctrl-E for paste mode
>>> CONTROLLER_CONFIG = {
... 'ID': 1986,
... 'CE': 1,
... 'NI': 'Controller',
... 'AP': 4
... }
>>> def configure_node(**kwargs):
... for cmd, value in kwargs.items():
... print(cmd, ' ', value)
...
...
...
>>> configure_node(**CONTROLLER_CONFIG)
ID 1986
AP 4
NI Controller
CE 1
>>>
I don't know much about MicroPython-on-xbee. As far as I know Digi haven't ever released source code for it? I wonder if maybe there's some feature they're disabling that's changing the behaviour of kwargs?
Maybe can you try running:
Code: Select all
CONTROLLER_CONFIG = {
'ID': 1986,
'CE': 1,
'NI': 'Controller',
'AP': 4
}
def configure_node(**kwargs):
print(kwargs)
Re: KeyError that I don't Understand
Not just on the simulator:
MicroPython v1.12 on 2019-12-20; ESP module with ESP8266
Type "help()" for more information.
>>>
>>> CONTROLLER_CONFIG = {
... 'ID': 1986,
... 'CE': 1,
... 'NI': 'Controller',
... 'AP': 4
... }
>>> print(CONTROLLER_CONFIG)
{'ID': 1986, 'AP': 4, 'NI': 'Controller', 'CE': 1}
>>> def configure_node(**kwargs):
... for cmd, value in kwargs.items():
... print(cmd, " ", value)
...
...
...
>>> configure_node(**CONTROLLER_CONFIG)
ID 1986
AP 4
NI Controller
CE 1
>>>