[Tutor] question about glob.glob() implementation

Sean 'Shaleh' Perry shaleh@valinux.com
Fri, 16 Feb 2001 08:15:39 -0800 (PST)

On 16-Feb-2001 Bruce Sass wrote:
> On Thu, 15 Feb 2001, Sean 'Shaleh' Perry wrote:
>> glob.glob() has a section like:
>> if not has_magic(basename):
>>         result = []
>>         for dirname in list:
>>             if basename or os.path.isdir(dirname):
>>                 name = os.path.join(dirname, basename)
>>                 if os.path.exists(name):
>>                     result.append(name)
>> else:
>> For every iteration of the for loop, basename is tested, yet its value never
>> changes.  Am I missing something here or is this wasteful like i think it
>> is?
> Hmmm, it looks like a dual purpose routine.  If basename is an empty
> string, result ends up with the paths to the dirs in list that exist
> (i.e., where can I look?).  If basename has a value, result ends up
> with the paths that end in basename (i.e., is it there?).

Could use a comment then.  What it looks like it is doing is making sure it is
not using an empty basename string.  And since the basename value never changes
the check seems superfluous.  I still feel this could be better coded, although
I am struggling to find the answer.  Thanks for the help.