[Tutor] searching in files
Alan Gauld
alan.gauld at blueyonder.co.uk
Thu Aug 12 00:13:20 CEST 2004
> I am writing a programme which includes searching some words in a
txt file...
> How can I do this?Is there a module in python which can do that?
You can search for strings using the builtin string mehods, so if you
read() the file into a huge string its easy.
If you specifically want to search for *words* then you might want
to use the re module to search for regular expressions. More powerful,
slower for simple searches but faster for complex ones
- like limiting to whole words...
HTH,
Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld/tutor2/
More information about the Tutor
mailing list