This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: glob.glob inconsistent
Type: behavior Stage: needs patch
Components: Library (Lib) Versions: Python 3.3, Python 3.4, Python 2.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: amaury.forgeotdarc, eric.araujo, ezio.melotti, kveretennicov, norbidur, serhiy.storchaka
Priority: low Keywords: patch

Created on 2007-08-18 00:14 by norbidur, last changed 2022-04-11 14:56 by admin.

Files
File name Uploaded Description Edit
glob_preserve_sep.patch amaury.forgeotdarc, 2010-07-31 13:11 review
Messages (10)
msg32653 - (view) Author: norbidur (norbidur) Date: 2007-08-18 00:14
On windows, glob.glob gives different results if you use a wildcard or not and if you use unix-style paths.

exemple : 
import glob
print glob.glob("c:/tmp/3691674.jpg")
print glob.glob("c:/tmp/3691674.jpg*")
print glob.glob("c:/res.txt")
print glob.glob("c:/res.txt*")

gives :
['c:/tmp/3691674.jpg']
['c:/tmp\\3691674.jpg']
['c:/res.txt']
['c:/res.txt']


the two first calls give the same result but one with a platform specific separator, and not the other.
One can think that if there is no wildcard, this is normal behavior to return the path given to glob.glob but then I have the second inconsitency : in that case the last result should be c:\\res.txt.
msg108627 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2010-06-25 20:30
Hardly a show stopper. It's actually a problem(?) with ntpath.py.  It could be patched but is it worth it, as this would be yet more work for you guys doing the build/release process?  I'd close this on the grounds that it's not worth the effort.
msg111727 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2010-07-27 20:38
As no response to msg108627 I'll close this unless there are any objections.
msg111728 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-07-27 20:45
Some bugs take a long time to get fixed. I agree that three years is not a good score, but this really needs a test in order to get closed or fixed, so I’m reopening. Maybe the OP or you could add a test? :)
msg112151 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2010-07-31 13:11
Here is a test + patch, to preserve the separator. Of course this changes the current behaviour, like:
>>> glob.glob('/tmp/////foo*')
['/tmp/////foo1', '/tmp/////foo2']
msg172970 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012-10-15 13:58
The question is what result desirable for glob.glob("c:/tmp///3691674.jpg*"), ['c:/tmp///3691674.jpg'] or ['c:\\tmp\\3691674.jpg']?
msg172972 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012-10-15 14:08
I have added some comments in Rietveld.
msg172974 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012-10-15 14:16
Shell preserves the separators. Well, in any case we always can apply os.path.normpath() to result.
msg208324 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-01-17 07:33
Amaury, could you provide corrected patch?
msg235622 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-02-09 17:40
Ping.
History
Date User Action Args
2022-04-11 14:56:26adminsetgithub: 45322
2015-02-09 17:40:03serhiy.storchakasetmessages: + msg235622
2014-02-03 15:37:09BreamoreBoysetnosy: - BreamoreBoy
2014-01-17 07:33:51serhiy.storchakasetmessages: + msg208324
components: - Windows
versions: - Python 3.2
2014-01-09 19:42:50serhiy.storchakasetpriority: normal -> low
2012-10-24 09:25:12serhiy.storchakasetstage: test needed -> needs patch
2012-10-15 14:34:37ezio.melottisetnosy: + ezio.melotti
2012-10-15 14:16:22serhiy.storchakasetmessages: + msg172974
2012-10-15 14:08:57serhiy.storchakasetmessages: + msg172972
2012-10-15 13:58:25serhiy.storchakasetnosy: + serhiy.storchaka

messages: + msg172970
versions: + Python 3.3, Python 3.4, - Python 3.1
2010-09-27 20:39:02kveretennicovsetnosy: + kveretennicov
2010-07-31 13:11:51amaury.forgeotdarcsetfiles: + glob_preserve_sep.patch

nosy: + amaury.forgeotdarc
messages: + msg112151

keywords: + patch
2010-07-27 20:45:18eric.araujosetstatus: pending -> open
versions: + Python 3.1, Python 2.7, Python 3.2, - Python 2.6
nosy: + eric.araujo

messages: + msg111728
2010-07-27 20:38:06BreamoreBoysetstatus: open -> pending

messages: + msg111727
2010-06-25 20:30:00BreamoreBoysetnosy: + BreamoreBoy
messages: + msg108627
2009-04-07 04:04:06ajaksu2setstage: test needed
type: behavior
components: + Windows
versions: + Python 2.6, - Python 2.5
2007-08-18 00:14:50norbidurcreate