On Sun, 03 Jan 2010 01:10:51 +1100, Lie Ryan wrote: > On 1/2/2010 9:42 PM, Steven D'Aprano wrote: >> On Fri, 01 Jan 2010 15:27:57 -0800, myle wrote: >> >>> Why we should prefer ``if: ...'' over a ``try: ... except something: >>> pass'' block? >> >> We shouldn't, not in general. > > One exception (pun intended) is if the try-block have a side effect that > is difficult to cleanup cleanly.
What if the "if ..." test has a side-effect? This is an argument against side-effects, not against using exceptions. But of course you are right, there are lots of good reasons for choosing to use an if test rather than a try block, or vice versa. I would argue that the try block is generally more Pythonic, and should be preferred, but that doesn't mean that there aren't reasons for sometimes choosing other strategies instead. -- Steven -- http://mail.python.org/mailman/listinfo/python-list