import csv fo = open("result.txt", "w+") reader = csv.reader(open('test.csv')) for line in reader: Name = line[0] fo.writelines(['class ',Name,'{\n']) fo.writelines('};\n') fo.close()