Reading from text

bearophileHUGS at bearophileHUGS at
Tue Feb 17 12:48:21 EST 2009

> 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).

Files can be iterated line-by-line, so this idiom:

for line in file: ...

will give you the lines, with newline. Once you have debugged that,
you can use the standard module glob (
glob.html#module-glob ) to iterate on files.

If you have more problems, show use the code you have written and we
may suggest improvements.


More information about the Python-list mailing list