News for hackers. Stuff that matters.
Re:Python Idioms [pdf] by yetanotherphd on Thursday January 30, 2014 @10:29PM (#7155064)
These two comments together make a lot of sense.

When your try block is a single lookup, you might as well use an if statement or get. However, when the 'absolute minimum' is nontrivial try/except is still a good option, e.g.

  try:
      name = employee['name']
      first_name = name['first_name']
      last_name = name['last_name']
  except KeyError:
      print "Bad employee data"
      return

There are no comments on this comment yet.