[issue33275] glob.glob should explicitly note that results aren't sorted
Ben FrantzDale <b...@formlabs.com> added the comment: I looked into it a bit more. With python 2.7 on macOS High Sierra on APFS (Encrypted) with a FAT32 thumb drive... I have a directory that glob.glob('/Volumes/thumb/tmp/*') shows as sorted. I cp -r that to /tmp with bash. glob.glob('/tmp/tmp/*') is now not sorted. and cp -r /tmp/tmp /Volumes/thumb/tmp1. Then glob.glob('/Volumes/thumb/tmp/*') shows a different order, but if I cp -r /Volumes/thumb/tmp/ /Volumes/thumb/tmp2 then glob.glob('/Volumes/thumb/tmp2/*') is sorted by file name just like glob.glob('/Volumes/thumb/tmp/*'). I'm not sue what that's saying other than that glob.glob can return things out of order on FAT32. It appears that glob.glob's ordering agrees with that of ls -f ("unsorted"). -- ___ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue33275> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue33275] glob.glob should explicitly note that results aren't sorted
Ben FrantzDale <b...@formlabs.com> added the comment: Great point. Looks like the phrase is "in arbitrary order" in the docs for those (both 2.7 and 3), which is better than saying nothing. I'd still prefer a bit more specificity about the potential gotcha since "arbitrary" seems a lot less deterministic than "some file systems will give you sorted order, some won't". On Tue, Apr 24, 2018 at 9:41 AM, Serhiy Storchaka <rep...@bugs.python.org> wrote: > > Serhiy Storchaka <storchaka+cpyt...@gmail.com> added the comment: > > Are there such notes in the descriptions of os.listdir(), os.scandir(), > os.walk(), os.fwalk() and corresponding Path methods? If explicitly > document the sorting, this should be made for all files enumerating > functions. > > -- > nosy: +serhiy.storchaka > > ___ > Python tracker <rep...@bugs.python.org> > <https://bugs.python.org/issue33275> > ___ > -- ___ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue33275> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue33275] glob.glob should explicitly note that results aren't sorted
Ben FrantzDale <b...@formlabs.com> added the comment: Fascinating. That seems like an even wilder gotcha: It sounds like a script assuming sorted results would work in one directory (on one filesystem) but not on another. Or even weirder, if I had a mounted scratch partition, the script could work until I (or a sys admin) mounts a larger drive with a different filesystem on the same mountpoint. Yikes! Either way, this gotcha seems worth mentioning explicitly. -- ___ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue33275> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue33275] glob.glob should explicitly note that results aren't sorted
New submission from Ben FrantzDale <b...@formlabs.com>: The sortedness of glob.glob's output is platform-dependent. While the docs do not mention sorting, and so are strictly correct, if you are on a platform where its output is sorted, it's easy to believe that the output is always sorted. I propose we a Note maybe next to "Note: Using the “**” pattern in large directory trees may consume an inordinate amount of time." that says "Note: While the output of glob.glob may be sorted on some architectures, ordering is not guaranteed. Use `sort(glob.glob(...))` if ordering is important." This wrong assumption burned us when scripts inexplicably stopped working on OSX High Sierra. -- components: Library (Lib) messages: 315254 nosy: Ben FrantzDale priority: normal severity: normal status: open title: glob.glob should explicitly note that results aren't sorted type: enhancement versions: Python 2.7, Python 3.4, Python 3.5, Python 3.6, Python 3.7, Python 3.8 ___ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue33275> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com