As promised, here starts the ill-advised series of me reading the Standard Library documentation. First day: Built-In Functions, which I grouped by topic.

My personal highlight was learning about the two-argument version of iter():

· · Web · 6 · 1 · 10

November 30: Built-in types (and constants and exceptions). Highlights include my surprise at set operations taking any iterable when you spell them out (my_set.union([1,2,3]) works!)

December 1: Text processing services, with the modules: string, re, difflib, textwrap, unicodedata, stringprep, readline.

Highlights: Some string functions I didn't know about, a reminder that textwrap exists and is good, and difflib.get_close_matches()

December 2: Binary data services, namely struct and codecs. Not a lot this time, but that's only fair, because tomorrow is "data types" 😱

Highlights for today: Yet Another Format String Syntax, and also native support for ROT-13 let's go

December 3: The "data types" section, which was … a lot: datetime, calendar, collections, heapq, bisect, array, weakref, types, copy, pprint, reprlib and enum.

tl;dr: collections remains the best, enums are weird, and I have a decent grip on weakrefs now

With a full 13 minutes to go until midnight! December 4: maths.

Highlights include shameless tau propaganda, giggling at the reason that cmath exists, fraction.limit_denominator() 😍, and my eyes glazing over at the amount of statistics Python can do.

Proceeding: Python Functional Programming Modules, itertools and functools and operator (yes, the one you only ever use for sorting by a specific key).

Big learning day: I learnt about cached_property and lru_cache and singledispatch.

More than a week in, I'm switching to AoE submission mode 🤣

Today: File access modules, or: oh god, why are there SO MANY. Highlights include some neat shutil functions and also the huge comparison table for the os.path/pathlib overlap.

I published the blog post yesterday, but forgot to post here: Python Data Persistence Modules (aka: pickle and some even weirder stuff).

Next: Python data compression modules. Python has a CLI interface for compressing, listing and decompressing zip and tar archives, who knew!

TIL in Python: CSV, JSON and XML all live in different sections of the Python docs. Also, there are dataformats like netrc, xdr and plist. Also, use csv.DictReader/Writer!

And INI files can support variable expansion, what could possibly go wrong.

🤫 secrets! And other cryptographic service modules. Not a lot to say here, really, except that the secrets module exists and should be use for security-critical randomness.

I'm a day late, because this entry is about "operating system services", and that includes os, io, time, argparse, getopt, logging and its submodules, getpass, curses and submodules, platform, errno and ctypes. Whew.

Back on track thanks to the shortest section in the documentation tree: It's just context variables. It's a bit terse, so instead of my usual summary post, this is me trying to make sense of the whole thing.

I had to take a break for real life reasons, which came knocking and were not to be denied. Oops.

Aaanyway, I'm back and playing catch-up. This one's about concurrency, including threading, multiprocessing, concurrent, subprocess, sched and queue. Yes. Ouch.

Also included: The documentation LIED to me (or did not predict my hilariousness, at least).

@rixx "all the times I've used next() were... bad life choices" okay I used next() literally today and oof this is accurate

@leigh I knowwww! next() is always there for you, but it's not a healthy relationship, Leigh.

@rixx this is one of the *best kept* Python secrets, really :-)

@rixx When looking at the newest article is still the one from November 30th. Are the newer ones hidden?

@rixx Uh, out of interest. Do you have a practical use of ROT-13? Never saw a use case in IT for it.

@juli Haha, no, the only valid use of ROT-13 is to obfuscate spoilers in usenet (and maybe some forum?) posts.

@rixx FYI Just because I happen to have that in our code base:

`encoding.idna` apparently only supports an old deprecated RFC.

@don Oh wow, the documentation doesn't mention that at all. Thank you for telling me, will update the blog post.

@rixx Let's hope the claim made by the `idna` package is actually correct.

@don It's supported by another comment made by a Python core dev in a slightly related issue, so I assume so.

@rixx great, thank you. As may know, I work with schedules and often deal with reoccurring times. Do you know of data types and libraries to deal with "anyday 8:00:03.45 localtime"?

@joshi You can localize to the target time and then compare the time tuples, that ought to match your usecase, shouldn't it?

@joshi For more specific recurring times, you probably want rrules though. The dateutil package has a decent implementation.

@rixx No joke: I had always assumed that cmath was just a faster implementation of math (written in C).

Now I wonder what other misconceptions your blog series will uncover...

@rixx Used fractions for the first time in my life today. Thanks for the well-timed reminder of their existence :'D

@rami @rixx at first I thought you meant the mathematical concept of fractions and I was like "what? how"

@rixx really useful, thanks! Also - a bit offtopic but your blog layout feels like a medieval book which is awesome

@michel_slm Thanks! I put an unreasonable amount of time into it and my inner history nerd clearly got the upper hand.

@rixx Not sure if that's on purpose, but the introductory post ( has not been updated.

(I'm keeping the link in my startup tabs so I don't miss a new entry even when I don't check twitter/masto for a few days)

@bmispelon Yeah, I forgot yesterday – update will come with the new post.

@rixx I remember post, I used it for a configuration file ages ago. Wasn't it oddly lisp-y?

@rixx Uh, man kann logging auf `str.format` umstellen? Gut zu wissen.

@rixx "There are way too many ways to start new processes in Python." Ohhh yes, definitely. The standard C library already has the same problem…

@daniel_bohrer Yes, but imagine not keeping them as single functions in python, and instead exposing a single interface with arguments...

@rixx You mentioned the password support of zipfile. The docs don't expressly state it, but it only supports unpacking password-protected zip archives, but not creating them. The reasoning afaik is that the encryption is so weak, they do not want to support creating such zip files.

@rixx @vollkorn I just thought this might be worth mentioning to avoid cofusion or disappointment.

@vollkorn Oh huh! Yeah, thanks for bringing that up, good to know

@rixx One thing that helps me remember the order of arguments for `map` is the fact that it can actually take multiple iterables as arguments: `map(fn, iter1, iter2, iter3, ...)` is the same as `[fn(x, y, z) for x, y, z in zip(iter1, iter2, iter3)]`

Because of this, it makes sense (to me at least) that the function should be the first argument.

@bmispelon True, thanks! It's just that I'm thinking "map x to y" m)

Sign in to participate in the conversation – a Fediverse instance for & by the Chaos community