I wrote this program to read a text file and put the contents line by line into another cvs file for writing. However, I would like to open the first txt file for reading, open another txt file for writing, and copy the contents of txt file 1 into txt file 2 without commas. For example, a line "1, 2, hello" should read "1 2 hello". I currently have it opening a csv file for writing, but I would like it to open a txt file for writing.
import csv
with open('texfile.txt', 'r') as in_file:
stripped = (line.strip() for line in in_file)
lines = (line.split(",") for line in stripped if line)
with open('csvfile.csv', 'w') as out_file:
writer = csv.writer(out_file)
writer.writerows(lines)