list(os popen( ' :\cygwin\bin\ls parts/part*')['parts/part \ ''parts/part \ ''parts/part \ ''parts/part \ 'the next two alternative techniques do better on both counts the glob module the term globbing comes from the wildcard character in filename patternsper computing folklorea matches "globof characters in less poetic termsglobbing simply means collecting the names of all entries in directory--files and subdirectories-whose names match given filename pattern in unix shellsglobbing expands filename patterns within command line into all matching filenames before the command is ever run in pythonwe can do something similar by calling the glob glob built-in-- tool that accepts filename pattern to expandand returns list (not generatorof matching file namesimport glob glob glob('*'['parts''pp ''random bin''spam txt''temp bin''temp txt'glob glob('bin'['random bin''temp bin'glob glob('parts'['parts'glob glob('parts/*'['parts\\part ''parts\\part ''parts\\part ''parts\\part 'glob glob('parts\part*'['parts\\part ''parts\\part ''parts\\part ''parts\\part 'the glob call accepts the usual filename pattern syntax used in shellsmeans any one charactermeans any number of charactersand [is character selection set +the pattern should include directory path if you wish to glob in something other than the current working directoryand the module accepts either unix or dos-style directory separators (or \this call is implemented without spawning shell command (it uses os listdirdescribed in the next sectionand so is likely to be faster and more portable and uniform across all python platforms than the os popen schemes shown earlier technically speakingglob is bit more powerful than described so far in factusing it to list files in one directory is just one use of its pattern-matching skills for instanceit can also be used to collect matching names across multiple directoriessimply because each level in passed-in directory path can be pattern toofor path in glob glob( 'pp \examples\pp \*\spy')print(path+in factglob just uses the standard fnmatch module to match name patternssee the fnmatch description in ' find module example for more details file and directory tools