3 ms·
Some batteries are surprising https://docs.python.org/3/library/ https://docs.python.org/3/library/ difflib - Text diffs, even html output textwrap - obvious
by aitchnyu 7y ago
Some batteries are surprising https://docs.python.org/3/library/ https://docs.python.org/3/library/
difflib - Text diffs, even html output
textwrap - obvious no?
rlcompleter - autocomplete symbols and identifiers, used in interactive mode
pprint - for printing complex data structures with indentation
reprlib - repr with traversal depth and string size limits
fraction - Fraction('-.125') becomes Fraction(-1, 8)
statistics - averages and deviances
tempfile — Generate temporary files and directories
glob — Unix style pathname pattern expansion
gzip, bz2, zipfile, tarfile - obvious
configparser - ini-like format
secrets - use this instead of random for safe cryptography
sched — Event scheduler
turtle — Turtle graphics
shlex — Simple lexical analysis
webbrowser — Convenient Web-browser controller, for the antigravity module!
- jimbo1qaz 7y agoLZMA is better than gzip i think. Also secrets deserves to stay in the library, Python has hashlib and it should have a secure RNG by default. glob too (or Path.glob). And I've used shlex for command-line-escape parsing (it might not have been the optimal solution?)
- masklinn 7y ago> LZMA is better than gzip i think. LZMA provides much better compression at much higher costs. Generally speaking it's pretty strictly better than bzip2, not necessarily gzip (DEFLATE, really). In my experience, zstd can be considered better than gzip/deflate (almost every time I tried it, it provided as-good-or-better compression at much faster throughput).
- maxnoe 7y agoYes, zstandard turned out to be the best option in all our tests on small to really large data (couple of mb to gigabytes filesize). A few percent better compression than gzip and nearly 50 % faster decompression. Gzip is pretty slow in the python standard lib. The python zstandard bindings unfortunately do not allow back seeking.
- int_19h 7y agoTurtle graphics is really handy for teaching programming. And it's important for new users to have minimal friction when setting things up, so having it in stdlib does make sense.
- Spiritus 7y agoSurprising how? I've used most of the "batteries" you mentioned in the past year.
- sametmax 7y agotextwrap - used by Python itself for docstring. rlcompleter - used by Python itself for the shell. pprint - trememdously useful for debugging. statistics - added recently because people kept rewritting mean() functions that were broken tempfile.gettempdir(), glob("*.ext"), gzip, bz2, zipfile, and tarfile are kinda mandatory for a language you use massively for scripting secrets - we had random. People used it for security all the time and created stupid security holes. So we added this. webbrowser — fantastic module that open a new tab in the default browser from any code. It's one file, so for the value it provides, I'm happy it is here.