victorg <[email protected]> added the comment:
Allow negative indexes that could be usefull.
Example: to compare 2 or more Path, if they come from the same top directory
from pathlib import Path
a = Path("/a/testpy/cpython/config.log")
b = Path("/b/testpy/cpython/config.log")
c = Path("/a/otherfolder/text.txt")
print(f"a.parents[-2] == b.parents[-2] -> {a.parents[-2] == b.parents[-2]}") #
False
print(f"a.parents[-2] == c.parents[-2] -> {a.parents[-2] == c.parents[-2]}") #
True
# index = -2 because -1 is "/"
----------
nosy: +victorg
Added file: https://bugs.python.org/file48949/allowNegativeIndexParents.patch
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue21041>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com