fastest way to test file for string?

Hendrik van Rooyen mail at
Fri Jun 5 11:37:25 EDT 2009

"kj" < at> wrote:
> Hi.  I need to implement, within a Python script, the same
> functionality as that of Unix's
>    grep -rl some_string some_directory
> I.e. find all the files under some_directory that contain the string
> "some_string".
> I imagine that I can always resort to the shell for this, but is
> there an efficient way of doing it within Python?
> (BTW, portability is not high on my list here; this will run on a
> Unix system, and non-portable Unix-specific solutions are fine with
> me.)

Use grep. You will not beat it's performance.

- Hendrik

More information about the Python-list mailing list