On 22 nov, 13:07, "Steve McConville" <[EMAIL PROTECTED]> wrote: > > 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
It isn't. In the first case, you only lookup the class dict, while the second takes inheritence, per-object methods, __getattr__ hooks etc into account. > Don't know if anyone would consider it more elegant Definitively not. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---