[Python-Dev] New syntax for 'dynamic' attribute access (original) (raw)

Greg Ewing greg.ewing at canterbury.ac.nz
Wed Feb 14 01:24:30 CET 2007


Martin v. Löwis wrote:

Apparently, people favor hasattr over catching AttributeError. I'm not sure why this is - I would probably rewrite them all to deal with AttributeError if I use the new syntax in the first place.

Actually, I prefer using getattr with a default value over either of those, wherever possible. AttributeError can be raised by too many things for me to feel comfortable about catching it.

This suggests that any proposed getattr syntax should include a way of specifying a default value.

I'm still -1 on the basic idea, though, on the grounds of YAGNIOE (You Aren't Going to Need It Often Enough).

-- Greg



More information about the Python-Dev mailing list