Python Forum
List of pathlib.Paths Not Ordered As Same List of Same String Filenames - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: List of pathlib.Paths Not Ordered As Same List of Same String Filenames (/thread-6224.html)

Pages: 1 2 3


RE: List of pathlib.Paths Not Ordered As Same List of Same String Filenames - QbLearningPython - Nov-16-2017

Thanks, @DeaD_EyE. Your explanation is very clear. You put on paper my suspicions about the mechanics of pathlib comparision.

However, I am not saying that there is anything buggy on pathlib. I am asking whether this should be the expected behaviour of comparing pathlib.Paths or not.

In my opinion, pathlib.Paths should be compared as a list of the string filenames to which they referred, not as a list of their parts (as you have clarified).

In python terms, for me this expression should be True:

sorted([str(path) for path in list_of_pathlib_paths]) == sorted(list_of_pathlib_paths)
Do you think that this would be a desirable result or not?

Among other things, for example, if filenames and pathlib.Paths are sorted in the same way, you can use a sorted list of sorted filenames to create a sorted list of pathlib.Paths without the need of re-sorting (do mathematicians call this isomorphism, a property of ordered bijection? --my school days were long ago).

I think that would be a great feature since pathlib.Paths and string filenames are used in many contexts as if they were the same thing (os and os.path modules, for instance).

What do you think?