def GetByPath(d, field_list):
  """Returns the value of a nested field of a dict of dicts."""
  for i, f in enumerate(field_list):
    try:
      d = d[f]
    except (KeyError, ValueError):
      # Re-raise with a more sensible error message.
      raise KeyError('Can\'t find field %s.' % '.'.join(field_list[:i+1]))
  return d