|
|
Subscribe / Log in / New account

Heinz: It's Time to Say Goodbye to These Obsolete Python Libraries

Heinz: It's Time to Say Goodbye to These Obsolete Python Libraries

Posted Jul 24, 2022 14:42 UTC (Sun) by randomguy3 (subscriber, #71063)
In reply to: Heinz: It's Time to Say Goodbye to These Obsolete Python Libraries by k8to
Parent article: Heinz: It's Time to Say Goodbye to These Obsolete Python Libraries

I think the main thing that makes the latter more readable is chaining functions rather than nesting them.

The specific names are secondary - but bear in mind many (maybe even most) python users are not well-versed in POSIX shells or libraries. I'm not sure there's much to choose between "resolve()" and the various other names that functionality has gone under in libraries throughout history, but I personally welcome "parent" and "filename".

Even after 20 years of using Linux, I still use basename when I want dirname, because it does the opposite of what I intuitively expect from its name. Dirname is less bad, but is still ambiguous when you know you're dealing with a path to a directory. They're just bad names, and I'm glad python took the opportunity to revisit them.

(FWIW, pathlib helpfully uses methods for filesystem operations and attributes for pure string manipulation, which makes the distinction easy to spot by looking for the parentheses. It really is a lovely, well-thought-out and well-documented library.)


to post comments

Heinz: It's Time to Say Goodbye to These Obsolete Python Libraries

Posted Jul 25, 2022 1:29 UTC (Mon) by NYKevin (subscriber, #129325) [Link]

> (FWIW, pathlib helpfully uses methods for filesystem operations and attributes for pure string manipulation, which makes the distinction easy to spot by looking for the parentheses. It really is a lovely, well-thought-out and well-documented library.)

This also comports nicely with standard Python idioms: Attributes are supposed to be cheap and free of side effects, whereas method calls can be costly or impure (for example, some systems may update atime on some filesystem operations, but string manipulation is definitely not going to do that).


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds