[New-bugs-announce] [issue21748] glob.glob does not sort its results

David Jones report at bugs.python.org
Fri Jun 13 15:31:43 CEST 2014


New submission from David Jones:

```
for f in glob.glob('input/*/*.dat'): print f
```

outputs:

```
input/ghcnm.v3.2.2.20140611/ghcnm.tavg.v3.2.2.20140611.qca.dat
input/ghcnm.v3.2.2.20140506/ghcnm.tavg.v3.2.2.20140506.qca.dat
```

Note that these are not in the right order.  Compare with shell which always sorts its globs:

```
drj$ printf '%s\n' input/*/*.dat
input/ghcnm.v3.2.2.20140506/ghcnm.tavg.v3.2.2.20140506.qca.dat
input/ghcnm.v3.2.2.20140611/ghcnm.tavg.v3.2.2.20140611.qca.dat
```

I think the shell behaviour is better and we should be allowed to rely on glob.glob sorting its result.

Note from the documentation: "The glob module finds all the pathnames matching a specified pattern according to the rules used by the Unix shell". The Unix shell has always sorted its globs.

----------
components: Library (Lib)
messages: 220441
nosy: drj
priority: normal
severity: normal
status: open
title: glob.glob does not sort its results
versions: Python 2.7

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue21748>
_______________________________________


More information about the New-bugs-announce mailing list