> Paul Boddie wrote: > >> I don't think I've ever seen anyone advocating calling a function like >> getattr(obj "foo" + "bar")(). > >> From Lib/compiler/visitor.py: > > meth = getattr(self.visitor, 'visit' + className, 0) > > Later on: > > meth(node, *args) > > Of course, you can drop the "visit" prefix and make the mechanism more > predictable, but a search on the standard library for getattr produces > a lot of evidence against your assertion. > I don't think you understood my assertion, then. The example that the original poster gave was using getattr() with a simple string ("foo" + "bar") for the 'name' argument, and without a default return value (as opposed to throwing a variable in there, or a string plus a variable like you did, or a default retval).
I even said you can do some "very powerful things" with getattr, by which I meant something exactly like you did. What did you think I meant by that? Jay P. -- http://mail.python.org/mailman/listinfo/python-list