[Catalog-sig] Need help on python´s glob module
Guido van Rossum
guido@digicool.com
Sun, 25 Mar 2001 11:58:00 -0500
> Hallo !
Hi Marcus!
You've posted this question to the wrong list. For questions like
this, please write to help@python.org -- or post to comp.lang.python.
> i´m programming a project in my graduation with python an need help on
> python´s glob module. I don´t know the search routine, in which python
> searches through different files.
> For example: I let python search through the actuall directory with the
> command *.out (which specifies all files ending of ".out"). There are
> three files in the actuall directory named: ist.out, soll.out and
> rc.out.
> First, python takes the "rc.out" file, then the "ist.out" file and at
> last the "soll.out" file. So, it seems not to be an alphabetical order,
> in which python searches through this files.
> Please, can you tell me the search routine for python´s glob module ?
>
> Thanks a lot
> Grettings
> Marcus Konermann
The source code for glob is in the file glob.py in the standard
library. The matching is actually done in fnmatch.py, but that
shouldn't matter. The search order you're seeing is because the files
aren't listed in alphabetical order in the directory (even though you
always get your directory listing from ls in alphabetical order -- ls
sorts the list itself).
It's easy to sort the list yourself, using the sort() method on lists:
>>> L = glob.glob("*.py")
>>> L
['rc.out', 'ist.out', 'soll.out']
>>> L.sort()
>>> L
['ist.out', 'rc.out', 'soll.out']
>>>
--Guido van Rossum (home page: http://www.python.org/~guido/)