It's also a really fun example of operator overloading. __div__
is overloaded to allow this syntax.
>>> p = PurePath('/etc')
>>> p
PurePosixPath('/etc')
>>> p / 'init.d' / 'apache2'
PurePosixPath('/etc/init.d/apache2')
Welcome to the Python community on the programming.dev Lemmy instance!
Past
November 2023
October 2023
July 2023
August 2023
September 2023
It's also a really fun example of operator overloading. __div__
is overloaded to allow this syntax.
>>> p = PurePath('/etc')
>>> p
PurePosixPath('/etc')
>>> p / 'init.d' / 'apache2'
PurePosixPath('/etc/init.d/apache2')
Disgusting. I love it!
There was a discussion of pathlib a few days ago: https://programming.dev/post/21864360
sorry, I was looking for it today, which prompted me to create this post
I subconsciously replace os.path
with pathlib
whenever touching any module for a refactor.
os
/os.path
functions are named after their C counterparts.
you can also enable this rule set to remind you https://docs.astral.sh/ruff/rules/#flake8-use-pathlib-pth
hell ye
They still messed up the default encoding though unfortunately.
π’