I have a text file which has the following data,
This is the pattern i have in my input file
1111
2222
3333
4444
5555
6666
7777
8888
9999
i want the output file to have the following:
1111222233334444
5555666677778888
9999
That is, i am trying to merge the 4 line into a single line and write it to my output file.
I have written the below code, but somwhow it is not doing the job.Can anybody help me?
def open_file(filename):
try:
mod_list= []
values = []
for line in file(filename):
line = line.rstrip()
mod_list.append(line)
i = iter(values)
for t in zip(*repeat(i, 4)):
print(''.join(t))
new_file.write(''.join(t))
new_file.close()
file(filename).close()
except Exception,e:
print str(e)
exit(1)