Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Some batteries are surprising 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!



textwrap - 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.


Surprising how? I've used most of the "batteries" you mentioned in the past year.


Turtle 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.


LZMA 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?)


> 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).


Yes, 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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: