grep

David Isaac aisaac0 at verizon.net
Tue Oct 25 17:07:58 EDT 2005


"Fredrik Lundh" <fredrik at pythonware.com> wrote::
    def grep(pattern, *files):
        search = re.compile(pattern).search
        for file in files:
            for index, line in enumerate(open(file)):
                if search(line):
                    print ":".join((file, str(index+1), line[:-1]))
    grep("grep", *glob.glob("*.py"))


I was afraid the re module was the answer.  ;-)
Use of enumerate is a nice idea.
Thanks.
Alan





More information about the Python-list mailing list