By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,818 Members | 1,347 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,818 IT Pros & Developers. It's quick & easy.

find.find

P: n/a
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
Jan 9 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
In <eo**********@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
Jan 10 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.