Python Forum
List of pathlib.Paths Not Ordered As Same List of Same String Filenames
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
List of pathlib.Paths Not Ordered As Same List of Same String Filenames
#21
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?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  question about changing the string value of a list element jacksfrustration 4 1,983 Feb-08-2025, 07:43 AM
Last Post: jacksfrustration
  Problem with pathlib ? Ota 3 1,272 Nov-11-2024, 06:04 AM
Last Post: MoMoProxy
  extract an element of a list into a string alexs 5 3,174 Aug-30-2024, 09:24 PM
Last Post: alexs
  comtypes: how to provinde a list of string to a COM method zalanthas 0 873 Jun-26-2024, 01:27 PM
Last Post: zalanthas
  Strange behavior list of list mmhmjanssen 3 1,529 May-09-2024, 11:32 AM
Last Post: mmhmjanssen
  Next/Prev file without loading all filenames WilliamKappler 9 3,097 Apr-12-2024, 05:13 AM
Last Post: Pedroski55
  Sample random, unique string pairs from a list without repetitions walterwhite 1 1,748 Nov-19-2023, 10:07 PM
Last Post: deanhystad
  trouble reading string/module from excel as a list popular_dog 0 884 Oct-04-2023, 01:07 PM
Last Post: popular_dog
  No matter what I do I get back "List indices must be integers or slices, not list" Radical 4 2,544 Sep-24-2023, 05:03 AM
Last Post: deanhystad
  String to List question help James_Thomas 6 2,328 Sep-06-2023, 02:32 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020