I have the following problem:
I need to load several data files. The files are named by my device like:
meas98.dat
meas99.dat
meas100.dat
meas101.dat
With other words, there are no leading zeros. Therefore, if I get the filenames via
os.listdir
they are ordered alphabetically, meaning "meas100.dat" will be the first one. This is obviously not what I want to achieve. The question is what is the most elegant way of doing this?
The (unelegant) way I came up with is:
- load the filenames
- extract the filenumber
- order the filenumber (get the indices)
- order the filenames with those indices
I am pretty sure python has something build in that can do this while loading the files...
Perhaps this will suit your problem:
Output: