Oct-22-2022, 06:21 AM
Or you could use an iterator and next.
# Read in all the lines delim = "," with open("data.csv", "r") as file: lines = iter(list(file)) with open("data.txt", "w") as file: # Strip spaces in header row file.write(",".join(map(str.strip, next(lines).split(delim)))+"\n") file.writelines(lines) # Copy other lines unchangedWhy do you want to leave spaces in the rest of the file?