binary key in dictionary
cerr
ron.eggler at gmail.com
Tue Jul 30 16:29:49 EDT 2013
Hi,
In my application I have followingf lines:
print curr_mac
print hexlify(buf)
binmac = unhexlify(curr_mac)
tmpgndict[binmac] += buf
curr_mac being a 3Byte MAVC address in ASCII and I want to populate a dictionary where the value(buf) is indexed by binary mac.
I get this in my code:
Traceback (most recent call last):
File "gateway.py", line 2485, in <module>
main()
File "gateway.py", line 2459, in main
cloud_check()
File "gateway.py", line 770, in cloud_check
gnstr_dict[src] = gn_from_cloud(curr_mac)
File "gateway.py", line 2103, in gn_from_cloud
tmpgndict[binmac] += "HELLO"
KeyError: '\x04\xeeu'
but then again, the following works fine in the python interpreter:
>>> mac = '04ee75'
>>> dat = '2a0001016d03c400040001000a'
>>> mydict = {}
>>> mydict[unhexlify(mac)]=dat
>>> print mydict
{'\x04\xeeu': '2a0001016d03c400040001000a'}
I really seem to do something wrong and can't see what it is. Can anyone help me further here?
Thank you very much!
Ron
More information about the Python-list
mailing list