What exception shall I raise when os.path.exists fails?

Peng Yu pengyu.ut at gmail.com
Thu Oct 29 01:01:00 EDT 2009


I want to raise an exception when os.path.exists fails. I looked
through the exception list on the menu. I'm not sure if IOError is the
most appropriate exception I should use. Could somebody let me know?
Thank you!

import os.path

def direct_target(path):
  while os.path.islink(path):
    path = os.path.join(os.path.dirname(path), os.readlink(path))

  if not os.path.exists(path):
    raise IOError
  else:
    return path



More information about the Python-list mailing list