Heinz: It's Time to Say Goodbye to These Obsolete Python Libraries
Using os.urandom isn't actually the problem here though, the reason the secrets module got introduced is because people were using the random module for generating passwords and such, even though the random module doesn't produce cryptographically safe tokens.
Posted Jul 20, 2022 17:16 UTC (Wed)
by domdfcoding (guest, #159754)
[Link] (1 responses)
Posted Jul 20, 2022 23:25 UTC (Wed)
by tialaramex (subscriber, #21167)
[Link]
The format would however work fine for announcing new libraries. A brief blurb about why could be useful in addition to the name of the library, but Python mostly doesn't have Rust's habit (which is divisive but I like it) of naming libraries based on puns, pop culture references etc. So a Python library for uploading Misc XML to the Cloud might be called Misc-XML-Cloud-Upload and it's redundant to say "For Uploading Misc XML to the Cloud" whereas the equivalent Rust library might be named stratus-various and a blurb helps us figure out whether we care.
Posted Jul 20, 2022 18:03 UTC (Wed)
by iabervon (subscriber, #722)
[Link] (6 responses)
Posted Jul 20, 2022 18:45 UTC (Wed)
by josh (subscriber, #17465)
[Link] (3 responses)
Posted Jul 20, 2022 19:32 UTC (Wed)
by mathstuf (subscriber, #69389)
[Link]
Posted Jul 22, 2022 23:44 UTC (Fri)
by jschrod (subscriber, #1646)
[Link] (1 responses)
Hooray for an integration programming language that combines the abstractions of CL with the system integration of Perl. It would be my dream language.
Posted Jul 24, 2022 5:58 UTC (Sun)
by CChittleborough (subscriber, #60775)
[Link]
Posted Jul 20, 2022 19:37 UTC (Wed)
by developer122 (guest, #152928)
[Link]
Posted Jul 21, 2022 1:13 UTC (Thu)
by cjwatson (subscriber, #7322)
[Link]
Posted Jul 20, 2022 21:29 UTC (Wed)
by k8to (guest, #15413)
[Link] (7 responses)
Posted Jul 21, 2022 0:15 UTC (Thu)
by neggles (subscriber, #153254)
[Link] (4 responses)
Pathlib is very well documented - and parent == dirname, same operation. It’s effectively a string replace, taking the full path and removing everything after and including the last forward slash. You can cast a Path to a string (or a string to a Path) whenever you like, too, so it’s not like you can’t do horrible string replacement shenanigans if you really must.
But Path objects (and chaining them with methods, rather than nesting a kshjillion functions) are a massive improvement over dealing with raw path strings, especially once symlinks and OS differences are involved - with Pathlib you just use forward slashes and forget about it. And it’s in the standard library! no dependencies! There’s no downside here!
it hurts me every time I see someone import sys and os just to deal with file paths, and all the gymnastics they go through to make things work properly… I’ve refactored many scripts and small modules to use Pathlib and in doing so usually replaced 2-6 lines of confusing code with a single line that’s easy to follow
Posted Jul 21, 2022 7:04 UTC (Thu)
by egorovv (subscriber, #102560)
[Link] (3 responses)
Posted Jul 21, 2022 9:34 UTC (Thu)
by mbunkus (subscriber, #87248)
[Link] (2 responses)
On top of that the vast majority of humans never uses shells. If they ever learn about file names & paths, they will most likely think of different directories & different files as separate entities. When does a regular (non IT person, non admin) Windows user ever come into contact with a full path such as C:\users\mbunkus\Documents\My Funny Valentine.txt? They use file dialogs, they use Windows explorer, and in both cases each element is presented as a distinct entity. They click on the "My Documents" icon. They click on the "My Funny Valentine.txt" document. I'd bet a lot of money that our notion of thinking of paths as strings is very, very foreign to them all.
Us shell users are the tiny minority.
Posted Jul 21, 2022 21:25 UTC (Thu)
by martin.langhoff (guest, #61417)
[Link] (1 responses)
Posted Jul 25, 2022 1:42 UTC (Mon)
by NYKevin (subscriber, #129325)
[Link]
* The attributes and division operator are all computed by pure string manipulation, and count as neither a "check" nor a "use" within the context of TOCTTOU. This is equivalent to calling functions such as os.path.join().
Posted Jul 24, 2022 14:42 UTC (Sun)
by randomguy3 (subscriber, #71063)
[Link] (1 responses)
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.)
Posted Jul 25, 2022 1:29 UTC (Mon)
by NYKevin (subscriber, #129325)
[Link]
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).
Heinz: It's Time to Say Goodbye to These Obsolete Python Libraries
Heinz: It's Time to Say Goodbye to These Obsolete Python Libraries
Heinz: It's Time to Say Goodbye to These Obsolete Python Libraries
Heinz: It's Time to Say Goodbye to These Obsolete Python Libraries
Heinz: It's Time to Say Goodbye to These Obsolete Python Libraries
Heinz: It's Time to Say Goodbye to These Obsolete Python Libraries
Pathlib looks good to me
Heinz: It's Time to Say Goodbye to These Obsolete Python Libraries
Heinz: It's Time to Say Goodbye to These Obsolete Python Libraries
Heinz: It's Time to Say Goodbye to These Obsolete Python Libraries
Heinz: It's Time to Say Goodbye to These Obsolete Python Libraries
Heinz: It's Time to Say Goodbye to These Obsolete Python Libraries
I can imagine though that for someone learning about paths first time from pathlib - this may look like a neat idea.
Heinz: It's Time to Say Goodbye to These Obsolete Python Libraries
Heinz: It's Time to Say Goodbye to These Obsolete Python Libraries
Heinz: It's Time to Say Goodbye to These Obsolete Python Libraries
* Nearly every part of the pathlib API is either a pure string manipulation, has a non-OO os.path equivalent, or both.
* pathlib does expose methods such as stat(), exists(), is_dir(), etc., but all of those methods have direct and straightforward os or os.path equivalents. pathlib does make them marginally easier to use, but that's just because the status quo ante was terrible (functions were randomly distributed between os and os.path with seemingly no rhyme or reason, so you had to memorize them or look it up).
* pathlib paths can be used in place of strings nearly everywhere. In particular, they are suitable arguments to open(), which can be called with mode='x' to get the equivalent of O_CREAT | O_EXCL if needed. This was already possible with strings, of course, pathlib just hasn't lost the ability to do it.
Heinz: It's Time to Say Goodbye to These Obsolete Python Libraries
Heinz: It's Time to Say Goodbye to These Obsolete Python Libraries
