getattr(object, attr)
getattr(odbchelper, "buildConnectionString")
type(getattr(object, method)) == types.FunctionType
True
Creating a Dispatcher with getattr
A statsout module defines three functions, output_html, output_xml, and output_text. Then the main program defines a single output function, like this:
import statsout
def output(data, format="text"):
output_function = getattr(statsout, "output_%s" % format)
return output_function(data)