The Most Diabolical Python Antipattern

Tim Chase python.list at tim.thechases.com
Thu Jan 29 12:32:38 EST 2015


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.

-tkc





More information about the Python-list mailing list