[Tutor] optparse

Alan Gauld alan.gauld at btinternet.com
Wed Dec 24 02:12:55 CET 2008


"Kent Johnson" <kent37 at tds.net> wrote

>>        for filename in os.listdir(directory):
>>            result = re.match(s, filename)
>>    print result
>
> You never open and read the files. You are searching for the pattern
> in the filename, not in the contents of the file.

Also note that match() only searches starting at the start of the 
string.

Thus match will find foo at

foobar

but not in

sofoo

You usually need to use search()  to find the pattern anywhere
within the string.

Also look at the thread earlier this week on using listdir() and
the fileinput module.

HTH,


-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 




More information about the Tutor mailing list