
On Tue, Jan 6, 2015 at 10:57 AM, Steven D'Aprano <steve@pearwood.info> wrote:
On Tue, Jan 06, 2015 at 04:14:38AM +1100, Chris Angelico wrote:
On Tue, Jan 6, 2015 at 4:10 AM, Steven D'Aprano <steve@pearwood.info> wrote:
* If you want to apply globs to something other than file names, the right module to use would probably be globbing.generic (or possible fnmatch directly).
Which module should you use [to match non-existing files]?
fnmatch. I've had a look inside glob.py and it calls os.listdir directly, so you cannot use glob to match things other than actual existing files. (Well, I suppose you could if you monkey-patched the module, but lets not go there.)
fnmatch, on the other hand, provides the right tool for matching names other than actual file names: fnmatch.filter(names, pattern). (Well, almost the right tool -- it has a few issues too.)
Ugh. That's poor naming, then. If this new globbing module happens, I would be a strong +1 on having 'globbing.generic' (or somesuch) to do this kind of thing, if only to fix the name. ChrisA