In some environments the files obtained with glob.glob
were in numerical order without doing anything, but in other environments they were not so arbitrary.
Source: http://stackoverflow.com/questions/12093940/reading-files-in-a-particular-order-in-python It is solved by sorting with reference to.
import glob
import re
def numericalSort(value):
numbers = re.compile(r'(\d+)')
parts = numbers.split(value)
parts[1::2] = map(int, parts[1::2])
return parts
fitsf=sorted(glob.glob('*.fits'), key=numericalSort)
Recommended Posts