loop though textfiles
Bernhard Reiter
bernhard at intevation.de
Mon May 14 10:59:57 EDT 2001
In article <i9SL6.10396$sk3.2792361 at newsb.telia.net>,
"Martin Johansson" <045521104 at telia.com> writes:
> How can I do if I want to do a searchmethon on several textfiles?
There are several possibilities.
> Can I use fileinput and how should I do?
Yes. Check my small snipplet and the fileinput documentation.
-----------
#! /bin/env python
"""" Per line processing example. """"
import sys
import string
import fileinput
filenames=["file1","file2","file3"]
def process(line):
""" Process one inputline and spit out, what we want. """
# get rid of the possible newline and the whitespace around chars
line=string.strip(line)
sys.stdout.write(line)
for lines in fileinput.input(filenames):
process(line)
-----------
> It must be some kind of loop.
Yes. :)
> this is the lines I want to do on every textfile.
The examples above should help you to get the right idea.
Bernhard
More information about the Python-list
mailing list