Reading from text

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Tue Feb 17 18:48:21 CET 2009


oamram:
> 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 (http://docs.python.org/library/
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.

Bye,
bearophile



More information about the Python-list mailing list