f



find.find

import fnmatch, os

def find(pattern, startdir=os.curdir):
     matches = []
     os.path.walk(startdir, findvisitor, (matches, pattern))
     matches.sort()
     return matches

def findvisitor((matches, pattern), thisdir, nameshere):  #
     for name in nameshere:
         if fnmatch.fnmatch(name, pattern):
             fullpath = os.path.join(thisdir, name)
             matches.append(fullpath)

can someone explain why (matches, pattern) is doing in this two funct?

thanks
0
gigs (81)
1/9/2007 10:46:45 PM
comp.lang.python 77058 articles. 5 followers. Post Follow

1 Replies
1162 Views

Similar Articles

[PageSpeed] 6

In <eo15uq$hna$1@ss408.t-com.hr>, Gigs_ wrote:

> import fnmatch, os
> 
> def find(pattern, startdir=os.curdir):
>      matches = []
>      os.path.walk(startdir, findvisitor, (matches, pattern))
>      matches.sort()
>      return matches
> 
> def findvisitor((matches, pattern), thisdir, nameshere):  #
>      for name in nameshere:
>          if fnmatch.fnmatch(name, pattern):
>              fullpath = os.path.join(thisdir, name)
>              matches.append(fullpath)
> 
> can someone explain why (matches, pattern) is doing in this two funct?

It's the first argument to `findvisitor()` which is invoked for every
directory level by `os.path.walk()`.  `findvisitor()` adds all file names
that match `pattern` to the `matches` list.

Ciao,
	Marc 'BlackJack' Rintsch
0
bj_666 (1523)
1/10/2007 12:13:38 AM
Reply: