I am running Python 2.5 (r25: 51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)] when winning 32
When I ask Python
>>> "u11-Phrase 099.wav" < "u11-Phrase 1000.wav" True
It's good. When I ask
>>> "u11-Phrase 100.wav" < "u11-Phrase 1000.wav" True
It's also good. But when I ask
>>> "u11-Phrase 101.wav" < "u11-Phrase 1000.wav" False
So, according to Python, "u11-Phrase 100.wav" precedes "u11-Phrase 1000.wav", but "u11-Phrase 101.wav" appears after "u11-Phrase 1000.wav"! And this is problematic for me, because I'm trying to write a file rename program, and such sorting violates the functionality.
What can I do to overcome this? Should I write my own cmp function and check for edge cases, or is there a much simpler shortcut to give me the order I want?
On the other hand, if I change lines like
>>> "u11-Phrase 0101.wav" < "u11-Phrase 1000.wav" True
However, these lines are taken from the list of directory files, for example:
files = glob.glob('*.wav') files.sort() for file in files: ...
Therefore, I would prefer not to do string operations after they were created by glob. And no, I do not want to change the original file names in this folder.
Any clues?
python sorting
Emre sevinç
source share