[Python-Dev] getattr vs hashattr

Chris Withers chris at simplistix.co.uk
Fri Mar 14 20:01:48 CET 2014


> On 03/12/2014 04:49 PM, Chris Angelico wrote:
>> You can use hasattr() in place of AttributeError

Is that true now? It used to be that hasattr swallowed all exceptions 
rather than just AttributeError making is a very dangerous weapon for 
anything (such as an orm or odb) that might do something interesting 
when you try and get an attribute from it.

On 12/03/2014 21:37, Tres Seaver wrote:
> I use:
>
>   getattr(subject, attrname, default)?
>
> *all the time*.

On this one, did anything ever come of making getattr have a default 
default of None?

Chris

-- 
Simplistix - Content Management, Batch Processing & Python Consulting
             - http://www.simplistix.co.uk


More information about the Python-Dev mailing list