def country(): if not os.path.exists('analytics'): os.mkdir('analytics') if os.path.exists('analytics/country'): shutil.rmtree('analytics/country') with open('studentinfo_cs384.csv', newline='') as csvfile: reader = csv.DictReader(csvfile) if not os.path.exists('analytics/country'): os.mkdir('analytics/country') for row in reader: l = list(row.values()) head = list(row.keys()) with open('analytics/country/'+row['country'].lower()+ '.csv', mode = 'a') as f: f_write = csv.writer(f, delimiter=',',lineterminator='\r') if os.path.getsize('analytics/country/'+row['country'].lower() + '.csv')==0: f_write.writerow(head) f_write.writerow(l) f.close() csvfile.close()