As promised, here starts the ill-advised series of me reading the #Python 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(): https://rixx.de/blog/first-sunday-of-advent-built-in-functions/
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. https://rixx.de/blog/december-1-python-text-processing-services/
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. https://rixx.de/blog/december-3-python-data-types/
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. https://rixx.de/blog/december-4-python-numeric-and-mathematical-modules/
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). https://rixx.de/blog/december-7-python-data-persistence-modules/
Next: Python data compression modules. Python has a CLI interface for compressing, listing and decompressing zip and tar archives, who knew! https://rixx.de/blog/december-8-pyton-data-compression-and-archiving-modules/
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. https://rixx.de/blog/december-9-python-file-format-modules/
🤫 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. https://rixx.de/blog/december-10-python-cryptographic-service-modules/
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. https://rixx.de/blog/december-11-python-operating-system-services/
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. https://rixx.de/blog/december-12-context-variables/
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
@rixx When looking at rixx.de/blog 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.
@don Oh wow, the documentation doesn't mention that at all. Thank you for telling me, will update the blog post.
@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
@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 "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 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.
chaos.social – a Fediverse instance for & by the Chaos community