Reg-Ex and lambda optimization

MikeCrowe mikecrowe at bigfoot.com
Sat Dec 29 19:19:02 EST 2001


Hi folks,

New to Python, and had this question.  I couldn't figure out how to read a directory and filter the results by what I wanted.  I basically wanted to read:
    dir\db*.*
and get all names of files matching that spec.  Here's the line I finally came up with:
    dbDirs = filter(lambda s: re.match('^db.*$',s), os.listdir(self.start))

I couldn't figure out how to us the FileList class, and this works.  Here's my question:

    Is the re.match('^db.*$',s) compiled each iteration of the loop lookup?

I don't notice this being slow, but was curious if this was bad coding.

Mike





More information about the Python-list mailing list