The Cost of Dynamism (was Re: Pyhon 2.x or 3.x, which is faster?)

Steven D'Aprano steve+comp.lang.python at pearwood.info
Mon Mar 21 02:38:38 EDT 2016


On Monday 21 March 2016 12:35, Chris Angelico wrote:

> On Mon, Mar 21, 2016 at 12:28 PM, Mark Lawrence <breamoreboy at yahoo.co.uk>
> wrote:
>> I got to line 22, saw the bare except, and promptly gave up.
> 
> Oh, keep going, Mark. It gets better.
[...]
> So, if any exception happens during the reading of the file, it gets
> squashed, and 0 is returned - which results in a generic message being
> printed, and the program terminating, with return value 0. Awesome!


While there is a certain level of entertainment to be gained from snarking 
at other people's bad code, and I'm as guilty as anyone else for doing so, 
please remember that Bart is engaged in a good-faith attempt to compare 
Python to other dynamic code. He's not claiming to be a Python expert or 
that he's writing idiomatic Python code.

Bart, bare except clauses are (as a general rule) an anti-pattern, and 
should be avoided except for the quickest and dirtiest of throw-away 
scripts. With very few exceptions (heh) you should *always* specify the 
narrowest set of exceptions that you know you can deal with.

Over-enthusiastic use of try...except is *deadly* for the ability to debug 
code:

https://realpython.com/blog/python/the-most-diabolical-python-antipattern/


-- 
Steve




More information about the Python-list mailing list