Path(filename) is an object and not a string.
If you take the string instead, the sort is identical.
If you take the string instead, the sort is identical.
paths_for_testing = [ str(Path(filename)) # <== take str(object) for filename in filenames_for_testing ]Windows 7 with Python 3.6.2:
Output:Ordered list of string filenames:
/spam/another.txt
/spam/binary.bin
/spam/spam.txt
/spam/spams.txt
/spam/spams/spam.ttt
/spam/spams/spam01.txt
/spam/spams/spam02.txt
/spam/spams/spam03.ppp
/spam/spams/spam04.doc
Ordered list of pathlib.Paths:
\spam\another.txt
\spam\binary.bin
\spam\spam.txt
\spam\spams.txt
\spam\spams\spam.ttt
\spam\spams\spam01.txt
\spam\spams\spam02.txt
\spam\spams\spam03.ppp
\spam\spams\spam04.doc