Here is my code:
import fileinput
input_file = 'in.txt'
output = open('out.txt', 'w+')
for each_line in fileinput.input(input_file):
output.write(x.strip() for x in each_line.split(','))
I get "expect character buffer" as the error. I am not sure what is the best way to go about this? I am trying to remove all tabs and spaces and replace them with a comma.
edit: forexample my data looks like:
1 2335 mike
1 4089 doug
and I want to turn it into
1,2335,mike noll
1,4089,doug funny
edit, i only want to remove the first 2 spaces in the first 2 columns
x.strip() for x in each_line.split(',')evaluates to a generator (which you can turn into a list by surrounding with[]s) butwrite()does not accept a generator.