Is there a way to get more specific Error messages in Python? E.g The full error code or at least the line the error occurred on, the exact file that cannot be found rather than a generic "The system cannot find the file specified")
for file in ['C:/AA/HA.csv', 'C:/AA1/HA1.csv']:
try:
os.remove(file)
except OSError as e:
pass
print(getattr(e, 'message', repr(e)))
#print(getattr(e, 'message', repr(e)))
#print(e.message)
#print('File Not Removed')
The following prints twice:
FileNotFoundError(2, 'The system cannot find the file specified')
While this is great, is there a way to get more precise error messages for bug fixing?
The following stops the job but gives out in console the exact line being 855 as well as the file directory ''C:/AC/HA.csv''.
os.remove('C:/AA/HA.csv')
Traceback (most recent call last):
File "C:/ACA.py", line 855, in <module>
os.remove('C:/AC/HA.csv')
FileNotFoundError: [WinError 2] The system cannot find the file specified: ''C:/AC/HA.csv''