python - what is the order in which glob.glob reads files? if there is no specific order, can one be specified? -


I use the following commands to read the names of all the files in a directory in Python:

< Pre> import glob list_of_files = glob.glob ("... / * .txt")

However the elements of the list "list_of_files" have no special order at least Nobody I can tell I-A do they read in alphabetical order? Or in the order of the last modified time stamp?

globe uses Oslistdir To get the filename to match, the document reads for listdir : "Return a list containing the names of entries in the directory given by the path. The list is in a voluntary order."

So you can not rely on any order - even if no one exists, it can be platform-specific and unbelievable. You need to sort the list of files based on criteria you want.

As far as I can see, there is no code in glob that changes its results. This is actually a very small module if you read it If you want to see what is happening under the hood.


Comments

Popular posts from this blog

Python Equivalent for matlab cart2pol and pol2cart -

sip - Call SipJs to Asterisk 12 -

java - Joda Time Interval Not returning what I expect -