While I'm -1 on the original proposal, I think the idea of PurePath.__len__ returning the number of components in the path may be worth some further consideration. Also, I'm not convinced that having indexing is a necessary prerequisite to pursue it further.
On Sun, May 24, 2020 at 8:14 AM Steven D'Aprano <[email protected]> wrote: > On Sun, May 24, 2020 at 02:27:00PM +0300, Ram Rachum wrote: > > > Today I wrote a script and did this: > > > > sorted(paths, key=lambda path: len(str(path)), reverse=True) > > > > But it would have been nicer if I could do this: > > > > sorted(paths, key=len, reverse=True) > > It would have been even nicer if we could compose functions: > > sorted(paths, key=lenāstr, reverse=True) > > *semi-wink* > > > > So I implemented `PurePath.__len__` as `str(len(path))`. > > > > Serhiy and Remi objected, because it might not be obvious that the length > > of the path would be the length of string. > > It isn't obvious to me that the length of a path is the length of the > string representation of that path. > > I thought that the length of the path would be the number of path > components: > > /tmp/file # length 2 > > I wouldn't have predicted that was the length of the string > representation of the path. > > > -- > Steven > _______________________________________________ > Python-ideas mailing list -- [email protected] > To unsubscribe send an email to [email protected] > https://mail.python.org/mailman3/lists/python-ideas.python.org/ > Message archived at > https://mail.python.org/archives/list/[email protected]/message/RHOPEZHLIPN5OVHNQGGT55VF5OBG4RJX/ > Code of Conduct: http://python.org/psf/codeofconduct/ >
_______________________________________________ Python-ideas mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/[email protected]/message/JMFSMAYRZ5QXVDJY44EYXS5RJH6WOGYY/ Code of Conduct: http://python.org/psf/codeofconduct/
