On Mar 30, 4:56 pm, "erikcw" <[EMAIL PROTECTED]> wrote: > Hi, > > I'm trying to create a multidimensional data structure. However, id > doesn't seem to work past the 2nd dimension. > > Here is my method: > > def endElement(self, name): > if name == 'row' : > if not self.data.has_key(self.parent): > self.data[self.parent] = {} > elif not self.data[self.parent].has_key(self.child): > self.data[self.parent][self.child] = [] > self.data[self.parent] > [self.child].append((self.creativeid, self.clicks, self.imps)) > > I've tried all kinds of different variations, and I keep getting the > same result: > > Traceback (most recent call last): > File "sax.py", line 123, in ? > parser.parse(open('report.xml')) > File "/usr/lib/python2.4/site-packages/_xmlplus/sax/expatreader.py", > line 109, in parse > xmlreader.IncrementalParser.parse(self, source) > File "/usr/lib/python2.4/site-packages/_xmlplus/sax/xmlreader.py", > line 123, in parse > self.feed(buffer) > File "/usr/lib/python2.4/site-packages/_xmlplus/sax/expatreader.py", > line 216, in feed > self._parser.Parse(data, isFinal) > File "/usr/lib/python2.4/site-packages/_xmlplus/sax/expatreader.py", > line 315, in end_element > self._cont_handler.endElement(name) > File "sax.py", line 51, in endElement > self.data[self.parent][self.child].append((self.creativeid, > self.clicks, self.imps)) > KeyError: u'Pickup Trucks' > > I have a lot of php experience - am I accidentally doing a "php thing" > in my code? > > Thanks so much for your help! > > Erik
I haven't tested it, but superficially I'd suggest giving this a try: def endElement(self, name): if name == 'row' : if not self.data.has_key(self.parent): self.data[self.parent] = {} if not self.data[self.parent].has_key(self.child): self.data[self.parent][self.child] = [] self.data[self.parent] [self.child].append((self.creativeid, self.clicks, self.imps)) -- http://mail.python.org/mailman/listinfo/python-list