The default RNG is not a CSPRNG:
> Python uses the Mersenne Twister as the core generator […] and [that generator] is completely unsuitable for cryptographic purposes.
These aren't "truly random passwords". Don't do this, use the generator included in a more … complete? mainstream? keyring program like LastPass. Or use a generator usable for cryptographic purposes.
Also, we get to see all the ways a language causes people to write code that just completely fails on any non-ASCII input:
> leftpad
With all the classic leftpad bugs:
In [4]: for s in ('asdf', '\N{PILE OF POO} asdf', 'e\N{COMBINING ACUTE ACCENT} asdf'): print(left_pad(s, 10))
asdf
asdf
é asdf
I am particularly unfond of leftpad as a token example of "look how easy this is" and the endless debates about "useless" dependencies that projects have, because the functions are so "simple". But they're only simple when you start removing essential complexity from the problem, and in doing so, introduce bugs.> palindrome
In [6]: is_palindrome('e\N{COMBINING ACUTE ACCENT}')
Out[6]: False
Unclosed file handles.I have coworkers who love copy/pasting code like this into real codebases, which is why this stuff sort of horrifies me.
Is showing a code snippet that would be buggy if it were what one would actually need actually worthwhile, just because it fits in a tweet? I care about how much code it takes to do something properly, sans-corner-cutting, in a given language.
> prettify JSON
( https://books.agiliq.com/projects/tweetable-python/en/latest... )
Interestingly, you can just pipe to json.tool:
<something that outputs JSON> | python -m json.tool
(There's also jq, which will additionally do syntax highlighting and is significantly shorter to type, so that's my usual go-to, but this is about Python specifically.)> convert CSV to sqlite, several other examples
There's just nothing here.