Searching for equivalent of FileNotFoundError in Python 2

If FileNotFoundError isn’t there, define it:

try:
    FileNotFoundError
except NameError:
    FileNotFoundError = IOError

Now you can catch FileNotFoundError in Python 2 since it’s really IOError.

Be careful though, IOError has other meanings. In particular, any message should probably say “file could not be read” rather than “file not found.”

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)