posting the code - further to odd problem
Hans Nowak
wurmy at earthlink.net
Sat Dec 29 03:26:20 EST 2001
Dave Harrison wrote:
> However the packet class code is as follows :
>
> import string
> pdic = {}
>
> class Packet:
> def __init__(self, info):
> self.buildDic(info)
>
> def buildDic(self, info):
> for item in info:
> split = string.split(item,"=")
> if (len(split) > 1):
> pdic[split[0]] = split[1]
>
> def getVal(self, key):
> if pdic.has_key(key):
> result = pdic[key]
> else:
> result = ''
> return result
It puzzles me how you can do
for pac in paclist:
print pac.getVal()
(as quoted from your previous post) and not get an error,
since getVal takes a key as its argument. Which leads me
to suspect that this wasn't actual code. :-)
Anyway, I don't know what kind of items Packet takes
(I got it to work with a list of strings like "a=1" etc),
so I cannot do much there. However, I do notice that
all packet instances share the same dictionary (pdic).
Maybe this has something to do with it? Packet has
no attributes, so I wonder where it takes its value
from.
--Hans
More information about the Python-list
mailing list