The Most Diabolical Python Antipattern

Ian Kelly ian.g.kelly at gmail.com
Thu Jan 29 17:51:28 EST 2015


On Thu, Jan 29, 2015 at 10:32 AM, Tim Chase
<python.list at tim.thechases.com> wrote:
> On 2015-01-29 17:17, Mark Lawrence wrote:
>> The author is quite clear on his views here
>> https://realpython.com/blog/python/the-most-diabolical-python-antipattern/
>> but what do you guys and gals think?
>
> I just read that earlier today and agree for the most part.  The only
> exception (pun only partially intended) I've found is in functions
> that need to return a defined type.  I have one that I call int0()
> that is my "give me a freakin' int" function which is something like
>
>   def int0(val):
>     try:
>       return int(val)
>     except:
>       return 0
>
> because I deal with a lot of CSV data from client/vendor that has
> blanks, "NULL", "---", and plenty of other rubbish to suggest
> something that, for my purposes is really just a 0.
>
> Yes, I've been stung by it occasionally, but it's not much trouble to
> see that I'm getting a 0 some place that should have a value I need
> to extract.

At least use "except Exception" instead of a bare except. Do you
really want things like SystemExit and KeyboardInterrupt to get turned
into 0?



More information about the Python-list mailing list