On 4/15/07, Chris Moffitt <[EMAIL PROTECTED]> wrote:
> Thanks for the pointer.  Any other ideas?


There are a few straight Python things you can do to speed up the code
a bit, but they won't be huge.

First off, how many keys are you usually seeing in
address.__dict__.keys()? If it's a lot, and the "if
data.has_key(field)" check is *usually* true, you might be better to
do:

for field in address.__dict__.keys():
    try:
        setattr(address, field, data[field])
    except KeyError:
        pass

Also, you might try .iterkeys() instead of .keys()

Second, in the big "else" block, you're doing too much string creation
in the for loop. Change it to:

for field in address.__dict__.keys():
    try:
        setattr(ship_address, field, data['ship_' + field])
    except KeyError:
        pass

This way, you're no longer doing the conditional has_key, and you're
also not creating the "ship_"+field string twice each time.

You could also change that .keys() to a .iterkeys().

What would possibly be even better is if at the beginning of the
function, you did something like:

customer_keys = customer.__dict__.keys()

And then used customer_keys in both of your for loops. That saves a
function call.

Again, these are all just little things, but depending on how many
'address' keys there are, and how likely the key is to appear in
'data', it might make a difference.

Jay P.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to