glob.fnmatch (was "search speed")
Tim Chase
python.list at tim.thechases.com
Sat Jan 31 08:45:46 EST 2009
rdmurray at bitdance.com wrote:
> Quoth Tim Chase <tim at thechases.com>:
>> PS: as an aside, how do I import just the fnmatch function? I
>> tried both of the following and neither worked:
>>
>> from glob.fnmatch import fnmatch
>> from glob import fnmatch.fnmatch
>>
>> I finally resorted to the contortion coded below in favor of
>> import glob
>> fnmatch = glob.fnmatch.fnmatch
>
> What you want is:
>
> from fnmatch import fnmatch
Oh, that's head-smackingly obvious now...thanks!
My thought process usually goes something like
"""
I want to do some file-name globbing
there's a glob module that looks like a good place to start
hmm, dir(glob) tells me there's a fnmatch thing that looks like
what I want according to help(glob.fnmatch)
oh, the fnmatch() function is inside this glob.fnmatch thing
so, I want glob.fnmatch.fnmatch()
"""
It never occurred to me that fnmatch was its own importable
module. <sheepish grin>
-tkc
More information about the Python-list
mailing list