Jay Parlar wrote: [...]
> >> getattr(obj "foo" + "bar")(). [...vs...] > > meth = getattr(self.visitor, 'visit' + className, 0) [...] > 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). Whether you evaluate the attribute lookup and immediately call the value returned, or whether you instead hold on to that value and invoke it later, is fairly unimportant when considering the behaviour of the program, but such distinctions are important if you wish to acknowledge the extent to which "dynamic" behaviour permeates running Python programs, especially if you're interested in analysing their behaviour at compile time. > 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? Exactly what I gave as an example. The original example was just badly formulated: two string literals glued together doesn't really capture the imagination. I doubt that many compiler writers and IDE makers seeking to improve their respective code generation and tooltip-popping experiences would make the handling of such contrived examples a priority - the possibilities presented by the general underlying mechanisms would be far more worrying. Paul -- http://mail.python.org/mailman/listinfo/python-list