I am trying to import a .csv file, clean the contents, and make sure all the errors are eliminated.
- IO error
- file format error
- data error
I am using the snippet below. Could someone help me clean it and make it more pythonic?
try:
fl = request.FILES['csv']
except:
return HttpResponse("Some IO Error")
try:
reader = csv.reader(fl)
except:
return HttpResponse("File Not Supported")
reader.next() # this makes sure the heading is
cleaned_csv_content = list()
for row in reader:
err = 0
fname, lname, e_mail = row
try:
validate_email(email)
except:
pass
err = 1
if not err:
cleaned_csv_content.append(fname, lname, e_mail)