Bengt Richter wrote: > or, if you _are_ willing to read in the whole file, > > open('text.txt').read().count('\n') Except the last line might not have a terminal newline. Andrew dalke at dalkescientific.com