`glob.glob()` uses `os.listdir()`, which includes borken symlinks in the listing if the pattern contains shell metacharacters but uses `os.path.exists()` which is False for broken symlinks if the pattern is a fixed name. Thus: >>> os.symlink('broken', 'sym1') >>> os.symlink('broken', 'sym2') >>> import glob >>> glob.glob('sym*') ['sym1', 'sym2'] >>> glob.glob('sym1') [] >>> glob.glob('sym2') []
Logged In: YES user_id=36166 This bug exists in all versions of the module since its creation up to 2.4. The correct behaviour (judging by the shell's behaviour - that's the model for the module, isn't it), is to always include broken symlinks in the results. Several fixes for this bug are provided by patch 941486 (http://python.org/sf/941486). [They all include the testcase attached here.]
Logged In: YES user_id=36166 What do you mean? Patch 941486 is there a long time already. Commit it (choose between the minimal fix and the more proper introduction of `os.path.lexists()`) and it'll be fixed. Then you could add patch 943206 if you like ;-). And I've refreshed both to apply cleanly against current trunk.
Logged In: YES user_id=469548 I think that question was directed at me (Raymond assigned the bug to me). Well, I didn't... yet. I've added a comment to #941486.
Logged In: YES user_id=80475 Sorry, my question was meant for Johannes who recently committed something symlink related. If his patch did not fix your issue, he is still the one who will need to review and apply the patch (I'm on Windows and don't have symlinks).