glob() recursively in directories

from fnmatch import fnmatch
import os


def glob_recursively(path, pattern):
    """Return matching files with full path as generator."""
    for name in os.listdir(path):
        fullname = os.path.join(path, name)
        if os.path.isdir(fullname):
            for f in glob_recursively(fullname, pattern):
                yield f
        elif fnmatch(name, pattern):
            yield fullname


# example
matches = glob_recursively('/some/path', 'example*.py')
for f in matches:
   print f