Reading from text

Paul McGuire ptmcg at austin.rr.com
Fri Mar 6 20:20:42 CET 2009


On Feb 17, 11:03 am, oamram <oam... at gmail.com> wrote:
> Hi All,
> new to python. i have a directory with about 50 text file and i need to
> iterate through them and get
> line 7 to 11 from each file and write those lines into another file(one file
> that will contain all lines).
>

import glob
file("output.txt","w").write('\n'.join( "".join(f.readlines()
[7:11+1]) ) for f in glob.glob("targetdir/*.txt"))

-- Paul



More information about the Python-list mailing list