[Tutor] Tutor Digest, Vol 25, Issue 83

Janesh Ramakrishnan jramakrishnan at neuropace.com
Fri Apr 7 02:16:04 CEST 2006


Hi Kent:

Thanks for your response. The Grep function does a really good job of searching across .py files in a directory or subdirectories for the specific keyword/string. 

In the PythonWin interpreter 2.1, Go to File -> New -> Grep and the search string can be entered. It is useful in searching strings across multiple files, especially in large projects.

~Janesh


Message: 1
Date: Thu, 30 Mar 2006 21:22:39 -0500
From: Kent Johnson <kent37 at tds.net>
Subject: Re: [Tutor] Searching across .Py files for a particular
	string/	character
Cc: tutor at python.org
Message-ID: <442C926F.3080007 at tds.net>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Janesh Ramakrishnan wrote:
> Hi Folks,
> 
> I was wondering what would be the best way to look up a string across
> 
different files in the Python interpreter (PythonWin 2.4). The find
function only finds files within currently open files. If I have a
folder of .py scripts and need to look up a specific keyword or string
among all these files within the project folder, is there any method
that you'd recommend?

I would do that in my editor, probably. But Python can get a list of 
files in a directory with os.listdir(). Loop over the files, use 
os.path.join() to make a full path, open the file, read the data, look 
for the string in the data.

Kent



More information about the Tutor mailing list