[Tutor] Space the final frontier

John Corry info at harrycorry.com
Wed Apr 5 09:46:51 CEST 2006


Dear All,

Thanks for the prompt replies.  I have now processed my file with 999 lines
and it took seconds.  It was beautiful.

Your advice was spot on.  I have enclosed the code that I ended up with.
Instead of appending it to a list, I just wrote it to another file in the
corrected format.


filename = "a:/calllist.csv"
filename2 = "c:/calllist.csv"
import string
import os
import re
listy = []
input = open( filename, 'r')	#read access
input2 = open(filename2, 'w')
for line in input.readlines():
    line = re.sub('[\s]+', '', line)
    y = line
    x = "\n"
    z = y + x
    input2.write(z)


del input
del input2

Thanks again,

John.





More information about the Tutor mailing list