<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Mar 14, 2014 at 3:01 PM, Chris Withers <span dir="ltr"><<a href="mailto:chris@simplistix.co.uk" target="_blank">chris@simplistix.co.uk</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
On 03/12/2014 04:49 PM, Chris Angelico wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
You can use hasattr() in place of AttributeError<br>
</blockquote></blockquote>
<br>
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.<br>
</blockquote><div><br></div><div>Changed in Python 3.2: <a href="http://docs.python.org/3.2/whatsnew/3.2.html">http://docs.python.org/3.2/whatsnew/3.2.html</a></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
On 12/03/2014 21:37, Tres Seaver wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
I use:<br>
<br>
getattr(subject, attrname, default)?<br>
<br>
*all the time*.<br>
</blockquote>
<br>
On this one, did anything ever come of making getattr have a default default of None?</blockquote><div><br></div><div>No. If you want None returned as the default you still need to specify that to allow for those APIs where the attribute can have a value of None but you still want it to raise an AttributeError if the attribute isn't there.</div>
<div><br></div><div>-Brett</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span class=""><font color="#888888"><br>
<br>
Chris<br>
<br>
-- <br>
Simplistix - Content Management, Batch Processing & Python Consulting<br>
- <a href="http://www.simplistix.co.uk" target="_blank">http://www.simplistix.co.uk</a><br>
______________________________<u></u>_________________<br>
Python-Dev mailing list<br>
<a href="mailto:Python-Dev@python.org" target="_blank">Python-Dev@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-dev" target="_blank">https://mail.python.org/<u></u>mailman/listinfo/python-dev</a><br>
Unsubscribe: <a href="https://mail.python.org/mailman/options/python-dev/brett%40python.org" target="_blank">https://mail.python.org/<u></u>mailman/options/python-dev/<u></u>brett%40python.org</a><br>
</font></span></blockquote></div><br></div></div>