[Python-ideas] Add OS-dependent automatic glob support

Steven D'Aprano steve at pearwood.info
Mon Jan 5 18:10:55 CET 2015

On Mon, Jan 05, 2015 at 01:19:16PM +0900, Stephen J. Turnbull wrote:
> Steven D'Aprano writes:
>  > In any case, having a platform specific globbing module
> By "platform-specific", do you mean one module that handles all
> platforms appropriately (what this thread is about), or do you mean
> per-platform modules (what "platform-specific" means to me)?

Yes to both.

The model I am proposing is that of the os and os.path modules: we 
import os and it does the right thing for the current platform. In 
particular, os.path will do the right thing for the current platform, 
but you can import ntpath, posixpath, genericpath etc. to get behaviour 
for a specific platform.

I think we have to leave the glob module as-is, for backwards 
compatibility, and add a new package, say globbing (or osglob, the name 
can be bike-shedded to death later *wink*) with the new behaviour. 
globbing will look something like this:


(plus any other platforms that may need special treatment, if any) and 
the globbing/__init__.py implementation could potentially be as simple 
as "from foo import *" from the appropriate sub-module.

The globbing.generic implementation might be as simple as:

from glob import *

Or perhaps the relationship should go the other way? Move the current 
glob.py implementation into globbing.generic, and replace it with:

from globbing.generic import *

These little details are to be decided later, but the aim is:

* Current code that imports glob will continue to work the same 
  as it does now, warts and all.

* Code that imports globbing will do the right thing for the

* 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).


More information about the Python-ideas mailing list