Hallo ! 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
glob returns an unsorted list of matching files. You can call the sort() method to get what you want: import glob filelist = glob.glob( '*.py' ) filelist.sort() for filename in filelist: # process filename... Enjoy ! Emmanuel
Dear Marcus, You might get better results if you ask tutor@python.org or comp.lang.python; edu-sig is meant for people talking about the educational aspects of teaching Python, so I'm not sure if anyone's here can help explain how glob.glob() works. On the other hand, comp.lang.python and tutor@python.org has a bunch of people that would be happy to help you out. You can contact both here: http://mail.python.org/mailman/listinfo/python-list http://mail.python.org/mailman/listinfo/tutor By the way, if you really want to see how glob.glob works, you can take a look at its source code; it itself is written in Python, which is nice. Try doing a search on your computer for the file "glob.py", and you should be able to find it. As far as I can tell, it's not alphabetic. It depends on the os.path functions and does lots of recursive stuff, but it doesn't seem to difficult to read. If you have any questions on it, please feel free to ask us on comp.lang.python or tutor. Good luck to you.
participants (3)
-
Daniel Yoo
-
Emmanuel Viennet
-
Marcus Konermann