The idea of making it easy blindly ignore all exceptions is not very interesting.<br><br><div class="gmail_quote">On Sat, Apr 25, 2009 at 7:25 PM, Steven D'Aprano <span dir="ltr"><<a href="mailto:steve@pearwood.info">steve@pearwood.info</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div class="im">On Sat, 25 Apr 2009 06:32:07 pm spir wrote:<br><br>
</div><div class="im">> if hasattr(doc, 'footer')<br>
> text += doc.footer<br>
<br>
</div>A third alternative is to make sure that doc.footer always exists, even<br>
if it is only the empty string, and then just write:<br>
<br>
text += doc.footer<br>
<br>
In many cases, I prefer that. I don't like attributes which sometimes<br>
exist and sometimes don't.</blockquote><div><br>It is a common case though and convenient to have a simple way to resolve it. Adding a statement level ? operator would be a mistake in my opinion because it clobbers the entire statement rather than just the specific. If only :-) there were a way to get an attribute while at the same time specifying the default value if the attribute didn't exist, say something like:<br>
<br> getattr(var, attribute [, default] )<br><br>Of course, I'd also it would make sense to also have:<br><br> getitem(var, index [, default] )<br><br>--- Bruce<br></div></div>