NameError: global name 'PermissionError' is not defined (python 2.x)
nameerror, permissions, python-2.x, python-3.x
Solution
This solved the issue for me for python 2.75 and 3.31:
from errno import EACCES, EPERM, ENOENT
def print_error_message(e, file_name):
#PermissionError
if e.errno==EPERM or e.errno==EACCES:
print("PermissionError error({0}): {1} for:\n{2}".format(e.errno, e.strerror, file_name))
#FileNotFoundError
elif e.errno==ENOENT:
print("FileNotFoundError error({0}): {1} as:\n{2}".format(e.errno, e.strerror, file_name))
elif IOError:
print("I/O error({0}): {1} as:\n{2}".format(e.errno, e.strerror, file_name))
elif OSError:
print("OS error({0}): {1} as:\n{2}".format(e.errno, e.strerror, file_name))
try:
...
except (IOError, OSError) as e:
print_error_message(e,full_name)
sys.exit()
except:
print('Unexpected error:', sys.exc_info()[0])
sys.exit()
Thoughts/comments/suggestions are welcome.
Problem
The following line: ``` except (IOError, PermissionError, FileNotFoundError) as e: ``` Gives the following error message when I run it with python 2.75: ``` NameError: global name 'PermissionError' is not defined ``` But everything runs fine with python 3.3. Thoughts/suggestions?