linux - Exploring a directory using a for loop in python - does the order change? -
one of folders has json files, , i'm reading data contain classification svm. question had based on code:
filename in os.listdir(os.getcwd()): if re.search('.json$',filename): try: open(filename) json_data: print filename
each time pipe output, find filenames printed in same order, so:
95231464576.json 131777220274261.json 17151210249.json 122624927762214.json 159287900855286.json 155273941171682.json 5265971983.json 169635939813776.json 159429967503904.json 169114363192327.json 170797436313930.json 155963124522916.json
there few text files, , python files in directory.
question here is: determines order in these files printed? for loop have way of looking files?
tried examining whether order based on size (max min or min max) or last modified(i had no reason these tests,i tried them since can't think of other insight).
tried snippet 4 times, , order same each time.
i have labelled classes in different folders, if can assured of order helpful in labeling training set(i don't know how idea is).
the order not defined, , depends on filesystem.
i remember reading, many years ago, 1 of improvements of ext3 on ext2 keeping pointer in directory listing , beginning next operation on entry. program stat() open() entry, scanning beginning of (internal) list occur twice ext2; ext3 second operation on desired entry making search fast. significant many files in directory.
the point being listing directory begin list of entries whereever pointer happened be. also, order in entries created may affect order. ls
program performs sort operation before producing output visually consistent , usable.
Comments
Post a Comment