I’m surprised that I get an error when checking if a certain value in in my dictionary like this:
if src in mac_dict:
I have filled up my dictionaary like this:
data = database.get(mac, "get_nodelist", version=1)
if data:
fh = StringIO(data)
version = ord(fh.read(1))
length = ord2b(fh.read(2))
length = length / 8
macs = {}
for i in xrange(0,length):
mac = fh.read(6)[-3:]
tdm = ord2b(fh.read(2))
macs[mac] = tdm
print hexlify(mac) + " - " + str(tdm)
fh.close()
fh = open("macs.bin","wb")
pickle.dump(macs,fh)
fh.close()
return macs
data contains 6 Bytes of mac adresses plus 2 Bytes of tdm in sa row. They seem to be decoded properly with the print statement but when I want to check if src (in binary) is part of mac_dict, my script throws an exception – even tho I definitely should be in there.. any hints?
Thank you!
Ron
You will need to do this to check if a value is present:
What your code is doing is checking if src is already in use as a key. The dictionary class also has an equivalent method: