Exception Handling For Reading In Csv
My program takes in input of the file name and makes some alterations to the file. In case the user enters the wrong name, I don't want my program to crash. Currently, my code is:
Solution 1:
Whenever possible you should try to be specific with your exception handling. Your code doesn't look quite right. import os
try:
df = pd.read_csv(os.path.join(directory, user_input))
except IOError as e:
# print e
Might be what you want.
Solution 2:
Your file path is formatted wrong.
'directory\\%s' % user_input
Post a Comment for "Exception Handling For Reading In Csv"