[rb-general] patching python glob

Bernhard M. Wiedemann bernhardout at lsmod.de
Wed May 24 21:42:27 CEST 2017


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


On 2017-05-24 14:21, Ximin Luo wrote:
> Contrary to what others were assuming, python's glob is *not*
> implemented in terms of the libc glob. You can verify this by
> reading the source code:
> 
> /usr/lib/python2.7/glob.py /usr/lib/python2.7/fnmatch.py
> 
> Python's glob is in fact not sorted, and using sorted() will do a
> locale-independent sort.
> 
> The libc glob is local-dependently sorted and you have to run it
> with LC_ALL=C.UTF-8 for reproducible results.
> 
> So, the patch seems fine to me. Though sorted(list(xx)) is
> redundant and you can just use sorted(xx) directly even if xx is a
> generator/iterator.

I refined the commit message some more and opened
https://github.com/python/cpython/pull/1794
together with http://bugs.python.org/issue30461

interestingly, python glob is using an os.scandir python function,
but when reading their posixmodule.c I saw it did not use the scandir
POSIX/libc function, but used plain opendir/readdir.

because POSIX scandir has a builtin sort option, too.
-----BEGIN PGP SIGNATURE-----

iF0EARECAB0WIQRk4KvQEtfG32NHprVJNgs7HfuhZAUCWSXiFwAKCRBJNgs7Hfuh
ZDI7AKCA97HcD6qMC0GSZ1SQXyOz+D6YCwCeNT2TtDdICm/Y1BkY2NEc82ydcFo=
=QuSp
-----END PGP SIGNATURE-----


More information about the rb-general mailing list