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 3 1426
On Mar 30, 4:56 pm, "erikcw" <erikwickst...@gmail.comwrote:
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))
On Mar 30, 5:23 pm, FlipFish2...@yahoo.com wrote:
On Mar 30, 4:56 pm, "erikcw" <erikwickst...@gmail.comwrote:
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))
That seems to have done the trick! I can't believe I spent all
afternoon trying to figure that out!! Thanks a million!
On Fri, 2007-03-30 at 14:34 -0700, erikcw wrote:
On Mar 30, 5:23 pm, FlipFish2...@yahoo.com wrote:
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))
That seems to have done the trick! I can't believe I spent all
afternoon trying to figure that out!! Thanks a million!
Since you're already using dictionaries, as an alternative solution you
could construct a single dictionary that is keyed on two-dimensional
tuples (also known as ordered pairs). Combine that with the setdefault
method to initialize new entries and you end up with something like
this:
def endElement(self, name):
if name == 'row':
entry = self.data.setdefault((self.parent,self.child),[])
entry.append(...)
-Carsten This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Frank Jona |
last post by:
Intellisense with C# and a multi-file assembly is not
working. With VB.NET it is working.
Is there a fix availible?
We're using VisualStudio 2003
Regards
Frank
|
by: JVarsoke |
last post by:
I'm trying to use pgpenvelope and I keep getting the message:
Can't locate loadable object for module String::Approx in @INC (@INC
contains: /usr/lib/perl5/5.8.0/i586-linux-thread-multi . . .
...
|
by: Ganbold |
last post by:
Hi,
I'm new to multi-threaded programming and reading the book "Programming
with POSIX Threads" and
trying to understand concepts and coding.
What I'm trying to do is to rewrite mysql client...
|
by: Joe |
last post by:
I have 2 multi-list boxes, 1 displays course categories based on a
table called CATEGORIES. This table has 2 fields CATEGORY_ID,
CATEGORY_NAME
The other multi-list box displays courses based on...
|
by: Bob Rock |
last post by:
Hello,
I was wondering when multi-file assemblies may be useful.
With multi-file assemblies you may place inside the same assembly
netmodules coded in different languages and as a consequence...
|
by: Mullin Yu |
last post by:
As subject. I have lots of VB6 dll and ocx files and they are
single-threaded as VB6 doesn't support multi-threaded indeed. Can I wrap
anything at .NET so that multi-threaded feature can be...
|
by: CindyH |
last post by:
Hi
Does anyone know how to create a multi column combo box from the same table?
Thanks,
Cindy
|
by: Kaz Kylheku |
last post by:
I've been reading the recent cross-posted flamewar, and read Guido's
article where he posits that embedding multi-line lambdas in
expressions is an unsolvable puzzle.
So for the last 15 minutes...
|
by: jim |
last post by:
Each night, a scheduled task copies certain information from an MS
Access db to a MySQL db that serves as a data warehouse. I would like
to begin replicating multi-value fields from Access to...
|
by: =?ISO-8859-1?Q?Tom=E1s_=D3_h=C9ilidhe?= |
last post by:
As far as I know, the C Standard has no mention of multi-threaded
programming; it has no mention of how to achieve multi-threaded
programming, nor does it mention whether the language or its...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |