find function

Mark McEahern mark at
Sun Jan 25 23:51:24 CET 2004

On Sun, 2004-01-25 at 16:25, Uwe Mayer wrote:
> Hi,
> is there for python a find() function, like the perl module Find or the
> command line tool find?


  import glob
  pattern = '*.pyc'
  for name in glob.glob(pattern):
    print name

glob's not recursive, though.  For that, consider os.walk:

  import os
  path = '.'
  extensions = ('.pyc',)
  for root, dirs, files in os.walk(path):
    for name in files:
      prefix, ext = os.path.splitext(name)
      if ext not in extensions:
      fullname = os.path.join(root, name)
      print fullname

The above code may have syntax errors since I didn't run it.

// m

More information about the Python-list mailing list