Your search query "linkto%3A%22glob%22" didn't return any results. Please change some terms and refer to HelpOnSearching for more information.
(!) Consider performing a full-text search with your search terms.

Clear message


The glob module lists names in folders that match Unix shell patterns.

If the elemental function emulating Unix bash `echo *` really is missing
from the 2.5 Python batteries included, then here's a brief clear way of
adding that function to Python.

Mind you, to date I've never written an elemental function for Python that
I haven't eventually found well-buried somewhere, e.g., os.urandom.

See also:
See also:

import glob

def hitlist(patterns, quiet = ''):

        Choose files and folders like Unix bash ls and rm -f do.

        That is, visit each pattern. Substitute the sorted list of files
        and folder that match if any files or folders do match. Leave
        patterns that match no files or folders in place unchanged
        ordinarily, but delete those patterns if asked to be quiet.

        See glob in: Unix man bash | col -b

        results = []

        for pattern in patterns:
                matches = glob.glob(pattern)
                if matches:
                        results += matches
                elif not quiet:
                        results += [pattern]

        return results

if __name__ == '__main__':

        import sys
        args = sys.argv[1:]

        if not len(args):
                print "Usage: python [-f] 'pattern'"

                quiet = args[0]
                patterns = args[1:]
                if quiet != '-f':
                        quiet = ''
                        patterns = args
                print quiet, patterns

                hits = hitlist(patterns, quiet)
                for hit in hits:
                        print hit


Unable to edit the page? See the FrontPage for instructions.