def blood_group(): if not os.path.exists('analytics'): os.mkdir('analytics') if os.path.exists('analytics/blood_group'): shutil.rmtree('analytics/blood_group') with open('studentinfo_cs384.csv', newline='') as csvfile: reader = csv.DictReader(csvfile) if not os.path.exists('analytics/blood_group'): os.mkdir('analytics/blood_group') for row in reader: l = list(row.values()) head = list(row.keys()) with open('analytics/blood_group/'+row['blood_group']+ '.csv', mode = 'a') as f: f_write = csv.writer(f, delimiter=',',lineterminator='\r') if os.path.getsize('analytics/blood_group/'+row['blood_group'] + '.csv')==0: f_write.writerow(head) f_write.writerow(l) f.close() csvfile.close() # Create the new file here and also sort it in this function only.