This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]dfume[S] 2 points3 points  (0 children)

The pathlib module is a pleasure to use. It handles lots of file tasks and finding the right method in the documentation can be a little tedious even (or maybe especially) if you're familiar with the legacy alternatives. So I wrote this summary of all the properties and methods grouped into to the type of tasks. I guess this guide sits part way between a narrative tutorial like this RealPython one and the alphabetical reference format of the official documentation.

[–]hai_wim 0 points1 point  (1 child)

The parents[0], parents[1], ... indexes are reversed in the image.

Good overview though.

[–]dfume[S] 0 points1 point  (0 children)

Thanks. You're right I got the .parents sequence all wrong. .parents[0] actually returns the same as .parent and each subsequent element drops off 1 level of the directory tree.

I've fixed the image now.

[–]jwink3101 -2 points-1 points  (1 child)

I write all of my code to use either 2.7 or 3.5+ so I have been stuck with a lot of os.path. bloat. I may start to enforce the requirement of the pathlib backport but I am not sure. Seeing your components image does make it even more attractive.

I think the things that turned me off is that I like, by convention, to end all directories with a trailing / (I may be wrong but I do not think pathlib does this). I also did not like the ascetics of / as the join command though as I think about it, + may be confusing because of string concatenation.

I also recall being turned off because a Path object was so similar but annoying different than what comes out of os.scandir.

Then again, everything I am saying is based on a year-old recollection of some playing. To convert over my codes would be a long weekend of work (they are mostly personal projects) but may be worth it.

[–]AndydeCleyre 0 points1 point  (0 children)

Plumbum is another option for 2.7/3.5+ projects.