mindly.social is one of the many independent Mastodon servers you can use to participate in the fediverse.
Mindly.Social is an English speaking, friendly Mastodon instance created for people who want to use their brains and their hearts to make social networking more social. 🧠💖

Administered by:

Server stats:

1.2K
active users

can someone sell me on why I should switch to #python 's Pathlib, from os.path? I have coworkers that use it but I absolutely hate the syntax and need some redeeming quality so I don't go rewriting all of their code.

rebinding characters that had very defined meanings to different semantics just because they happen to look like a Unix path separator is not my favourite.
galaxians.gardenAkkoma

@hexylena

I get not liking the "clever" overloading of the division operator. Luckily, you don't have to use it - you can pass a full path as a single string, or a list of strings, and it will Do The Right Thing:

>>> Path("/usr", "lib", "grub")
PosixPath('/usr/lib/grub')

>>> Path("/usr/lib/grub")
PosixPath('/usr/lib/grub')

pathlib is nice because it gives some better, high-level abstractions. Things like `path.relative_to(other_path)` are very natural to read.

[...]

C.

@hexylena

Having the whole hierarchy from your path up to the root in `path.parents` is extremely handy to iterate over. The path parts attributes like .stem, .name, .suffixes etc make for very readable code.

And IMHO, code like `path.is_relative_to(other_path)` is simply more readable than`os.path.is_relative_to(path, otherpath)`.