[Tutor] looking for a pattern in a lot of files

Max Noel maxnoel_fr at yahoo.fr
Mon May 23 00:28:57 CEST 2005


On May 22, 2005, at 21:07, Jonas Melian wrote:

> for line in fileinput.input(glob.glob(os.path.join
>         (dir_locales, "*_[A-Z][A-Z]"))):
>     if re.search("locale for", line):
>         print line

     If you're only looking for the occurrence of a string and not a  
regex pattern, you don't have to use regular expressions:


if "locale for" in line:
     print line


     Works just as well, and is faster.

-- Max
maxnoel_fr at yahoo dot fr -- ICQ #85274019
"Look at you hacker... A pathetic creature of meat and bone, panting  
and sweating as you run through my corridors... How can you challenge  
a perfect, immortal machine?"



More information about the Tutor mailing list