Cleaning up conditionals

Tim Chase python.list at tim.thechases.com
Sat Dec 31 15:41:21 EST 2016


On 2016-12-30 19:59, Deborah Swanson wrote:
> Similar, actually the same as Cameron suggested. I really need to
> revisit testing for empty. I probably rejected it early on for some
> bad reason (you don't understand everything that goes wrong when
> you're learning).

If your data is anything like what I often get, it had spaces in it,
and

  x = " "
  if x:
    print("yep")
  else:
    print("nope")

prints "yep".  So when processing data like this, I prefer to take a
cleaning pass over everything to strip out leading/trailing
whitespace before attempting to use any logic on it.

-tkc





More information about the Python-list mailing list