[Tutor] Searching across .Py files for a particular string/ character
Kent Johnson
kent37 at tds.net
Fri Mar 31 04:22:39 CEST 2006
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