You are printing your text, not writing it to the file object. Use fh.write()
to write lines to the file:
with open('D:\\outcome.txt', 'a') as fh:
fh.write('lines files %s: %d %s: %d\n' % (onlyfiles[i],len(ilines),onlyfiles[j], len(jlines)))
fh.write('adds: %d subs: %d eqs: %d ?:%d\n' % (n_adds, n_subs, n_eqs, n_wiered))
Alternatively, use the (more obscure and little-used) >>
print redirection syntax:
with open('D:\\outcome.txt', 'a') as fh:
print >> fh, 'lines files %s: %d %s: %d' % (onlyfiles[i],len(ilines),onlyfiles[j], len(jlines)))
print >> fh, 'adds: %d subs: %d eqs: %d ?:%d' % (n_adds, n_subs, n_eqs, n_wiered))
In both cases, I open the file here in append mode, to add new information rather than replace the file contents.
Alternatively, move the file opening outside of the for
loops to truncate it just once, then write lines to the file each loop iteration before closing it once after the loop has completed. The with
statement takes care of closing the file object for you when the with
block completes or is exited.