Re: dynamic method calling

2008-11-24 Thread bruno desthuilliers
On 22 nov, 02:38, 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: > push = getattr(self, 'get_%s_content' % self.n

Re: dynamic method calling

2008-11-24 Thread bruno desthuilliers
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

Re: dynamic method calling

2008-11-24 Thread bruno desthuilliers
On 22 nov, 14:05, Ivan Sagalaev <[EMAIL PROTECTED]> wrote: > Chris wrote: > > try: > > push = getattr(self, 'get_%s_content' % self.name) > > except AttributeError: > > raise "Method does not exist" > > if callable(push): > > push(**argv) > > There are a couple of problems with this co

Re: dynamic method calling

2008-11-23 Thread Ned Batchelder
getattr is definitely preferable to self.__class__.__dict__ --Ned. http://nedbatchelder.com Henry Andrews wrote: > I've aways been under the impression that direct use of __dict__ was > discouraged. Something along the lines of __dict__ being an > implementation detail while getattr and hasattr

Re: dynamic method calling

2008-11-23 Thread Henry Andrews
I've aways been under the impression that direct use of __dict__ was discouraged. Something along the lines of __dict__ being an implementation detail while getattr and hasattr are the proper interfaces. But I might be wrong. thanks, -henry On Nov 22, 4:07 am, "Steve McConville" <[EMAIL PROTEC

Re: dynamic method calling

2008-11-22 Thread Steve McConville
> 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__[met

Re: dynamic method calling

2008-11-22 Thread Ivan Sagalaev
Ivan Sagalaev wrote: > if hasattr(self, 'get_%s_content' % self.name): > raise Exception('Method does not exists') Typo: there should be `if not hasattr`, obviously. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Grou

Re: dynamic method calling

2008-11-22 Thread Ivan Sagalaev
Chris wrote: > try: > push = getattr(self, 'get_%s_content' % self.name) > except AttributeError: > raise "Method does not exist" > if callable(push): > push(**argv) There are a couple of problems with this code. 1. It's more readable to call hasattr than to catch an exception from

Re: dynamic method calling

2008-11-22 Thread Horst Gutmann
AFAIK no (except for perhaps some different exception handling but getattr is IMO the way to go), but what don't you like about this approach? -- Horst 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 ca

dynamic method calling

2008-11-21 Thread Chris
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: push = getattr(self, 'get_%s_content' % self.name) except AttributeError: raise "Method does not exist" if