[Python-Dev] Summary of "dynamic attribute access" discussion
Greg Ewing
greg.ewing at canterbury.ac.nz
Wed Feb 14 02:54:24 CET 2007
Guido van Rossum wrote:
> it means we'll be catching AttributeError
> instead of using "look before you leap", which if fine with me.
A thought on this: to avoid masking bugs, when catching
AttributeError you really need to isolate the getattr
operation so that it's on a line by itself, with no
sub-expressions, i.e.
try:
x = getattr(obj, name)
except AttributeError:
...
else:
...
If you're doing that, I see no significant lack of
readability in the getattr call that needs to be
remedied.
So I'm down to -2 now. :-)
--
Greg
More information about the Python-Dev
mailing list