Help with optimisation

special_dragonfly Dominic at
Mon Aug 13 16:48:08 CEST 2007

I know this might be a little cheeky, and if it is, please say, but I need a 
little hand optimising some code. For the simple reason that this is 
'company' code and I have no idea what I'm allowed to release and not as the 
case may be I've changed anything that could give an indication of the 
company - if that makes any sense...

for the code below:
text_buffer is a single record from an XML stream. I can't read in the 
entire XML at once because it isn't all available straight away, so I 
capture line by line, and when a full message is available I use parseString 
under the minidom API.
The SQL version is SQLite. It was recommended to me, and is adequate for the 
uses I put it to.
The function doesn't return anything, but it's called often enough and 
depending on the optimisation I'll be able to use the same style in other 
areas of the program.

previous code:
def CreatePerson(text_buffer):
    reflist = dom.getElementsByTagName('Country')
    Country = reflist[0].firstChild.nodeValue
    reflist = dom.getElementsByTagName('Age')
    Age = reflist[0].firstChild.nodeValue
    reflist = dom.getElementsByTagName('Surname')
    Surname = reflist[0].firstChild.nodeValue
    reflist = dom.getElementsByTagName('Forename')
    Forename = reflist[0].firstChild.nodeValue
    cursor.execute('INSERT INTO Person VALUES(?,?,?)', (Forename + "-" + 
Surname, Age, Country))

I've changed it now to this:
def CreatePerson(text_buffer):
    for element in elements:
        # I can get away with the above because I know the structure of the 
    cursor.execute('INSERT INTO Person 

They both seem ugly IMO (read: longer than intuitively necessary), and so I 
was wondering whether there was any way to combine Forename and Surname 
together within the Values list (think merge cells with the '-' in between) 
so I could use the unary(?) operator within the SQL?

I suppose if this is a cheeky request then I won't get any replies.
Thank you for any help

More information about the Python-list mailing list