469,271 Members | 892 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,271 developers. It's quick & easy.

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
Jan 9 '07 #1
1 2179
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.

Similar topics

1 post views Thread by Dan Jones | last post: by
reply views Thread by amit | last post: by
reply views Thread by AMIT PUROHIT | last post: by
5 posts views Thread by Mike Labosh | last post: by
3 posts views Thread by David T. Ashley | last post: by
reply views Thread by Derek | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.