[Python-ideas] Adding '**' recursive search to glob.glob

Steven D'Aprano steve at pearwood.info
Tue Jan 15 02:31:56 CET 2013


On 15/01/13 08:38, Greg Ewing wrote:
> Steven D'Aprano wrote:
>
>> Rather than a flag, I suggest a version number:
>>
>> glob.glob(pattern, version=1) # current behaviour, as of 3.3
>> glob.glob(pattern, version=2) # adds ** recursion in Python 3.4
>
> Yuck, then the reader has to know what features are
> enabled by which version numbers -- not something that's
> easy to keep in one's head.


True. But neither are a plethora of enable_feature flags. Is it
allow_recursion or allow_recursive or enable_double_star? Globbing
is not likely to be something that most people use often enough that
the name of the arguments will stick in their head. People will
likely need to look it up one way or the other.

All this assumes that we need to care about backward compatibility
of ** in existing globs. It does seem to be an unlikely thing for
people to write. If we don't, then no need for a flag at all.
Instead, we could raise a warning for globs with ** in 3.4, and
then drop the warning in 3.5.

Another option, is a new function. Bool parameters that do nothing
but change the behaviour of a function are somewhat of a mild
anti-pattern. Perhaps it is better to just keep glob.glob as is,
and add glob.recglob or rglob to support **.



-- 
Steven



More information about the Python-ideas mailing list