Dec-08-2018, 10:09 AM
Hi Python-forum,
My problem is that whenever an incorrect name "file.txt" is entered into my dataload function, it crashes instead of printing the error.
-mark
My problem is that whenever an incorrect name "file.txt" is entered into my dataload function, it crashes instead of printing the error.
import pandas as pd def dataLoad(filename): data = pd.read_csv(filename,",") try: data except FileNotFoundError: print("Sorry the file wasn't found") else: print("Data was succesfully loaded") return dataWhen I run it with a incorrect filename
dataLoad("thisfiledeosnotexist.txt")and this is what I get
Error:FileNotFoundError: File b'thisfiledeosnotexist.txt' does not exist
Thank you all for taking time reading my post and helping :) -mark