You must use a different output file name. Even if you want the name to be the same, you should use some temporary name and finally rename the file. Otherwise, you first need to read the file in memory
import csv with open('infile','r'), open ('outfile','w') as fin, fout: writer = csv.writer(fout, delimiter=' ') for row in csv.reader(fin, delimiter=' '): if row[2] == 'Central': writer.writerow(row)
San4ez
source share