[Python-Dev] The path module PEP

Jason Orendorff jason.orendorff at gmail.com
Wed Jan 25 17:12:00 CET 2006


On 1/25/06, Toby Dickenson <tdickenson at devmail.geminidataloggers.co.uk> wrote:
> On Tuesday 24 January 2006 20:22, BJörn Lindqvist wrote:
> >     #Replacing glob.glob
> >     glob.glob("/lib/*.so")
> >     ==>
> >     Path("/lib").glob("*.so")
>
> This definition seems confusing because it splits the glob pattern string in
> two ('/lib', and '*.so'). [...]

Well, let's make this look more like real code:

    #line 1
    LIB_DIR = "/lib"
    ==>
    LIB_DIR = Path("/lib")

    #line 296
    libs = glob.glob(os.path.join(LIB_DIR, "*.so"))
    ==>
    libs = LIB_DIR.files("*.so")

Clearer?  In d.files(pattern), d is simply the root directory for the
search.  The same is true of all the searching methods: dirs(),
walkfiles(), walkdirs(), etc.

I actually never use path.glob().  For example, here files() is
actually more accurate, and the word "files" is surely clearer than
"glob".  Given files(), dirs(), and listdir(), I have never found a
real use case for glob().

-j


More information about the Python-Dev mailing list