I am using a script with multiple built-in raised ValueErrors that loops over certain files in a folder. It checks for conditions and should report an error message for every file looped if this occurs.
However, it only shows one ValueError message of one file, instead of all errors. It still executes the loop for the other files. So for example, I have file a and b which should both generate an error, but python only shows the error message of file a. I already checked it by deleting file a, and after running the script it does generate an error message for file b
Part of my code is
for f_name in os.listdir(path):
if f_name.endswith('.xls'):
...
if a < 0:
raise ValueError('error')
else:
xxx
Does someone know how to display all errors?
I think you should try and except statement to find which file raise Exception. Use this.
try:
if a < 0:
raise ValueError('error')
else:
xxx
except ValueError:
print(a) #this will print which file isn't satisfying the condition