> On Sat, Nov 22, 2008 at 2:38 AM, Chris <[EMAIL PROTECTED]> wrote:
>> Hello everyone,
>> I have a quick python question. Is they a better way of calling a
>> method dynamically then what I have below? Is there a more elegant
>> approach? Thanks in advance.
>>

try:
    self.__class__.__dict__[method_name](self, argument)
except KeyError:
    #handle missing method
    pass

is pretty much equivalent to

try:
    getattr(self, method_name)(argument)
except AttributeError:
    # handle missing method
    pass

Don't know if anyone would consider it more elegant but it doesn't use
getattr :)

-- 
steev
http://www.daikaiju.org.uk/~steve/

--~--~---------~--~----~------------~-------~--~----~
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