has_method
Gandalf
gandalf at geochemsource.com
Tue Aug 31 09:25:18 EDT 2004
> Well, one way is try/except:
>
> try:
> a.someMethod(arg1, arg2)
> except AttributeError:
> print "Aarrgghh!"
>
But since I have my method name in a variable, it will be this way:
methods = dir(self)
if methodname in methods:
cmd = "self." + methodname
method = eval(cmd)
This is what I wanted to avoid - i.e. the use of eval. There must be an
easier and quicker way to do this.
More information about the Python-list
mailing list