In my prior post on using dateutil for time zone information in Python, I half-jokingly posted a bit at the end about the size of pickled pytz
tzinfo instances compared to pickled dateutil
tzinfo instance. Paul Ganssle later emailed me to speculate that pytz’s smaller size is due to the fact that pytz is storing the key (name) of the time zone when you pickle one of its instances, whereas a pickled dateutil instance has all of the information about its time zone.
I’m not one to ignore the generous gift of someone’s time and knowledge, so let me dig into that a bit further. (Though Paul emailed me about four months ago, so I guess I am one to postpone acknowledgment of said gift.)
The TL;DR here is that Paul is basically right, and understanding this difference could be useful if you find yourself pickling/unpickling
tzinfo instances from either library.
Paul Ganssle, current maintainer of dateutil, asked me to review my 2014 post “The Case for pytz over dateutil” because he believes that dateutil now addresses the concerns I had in my post that caused me to give a slight nod to pytz over dateutil. He’s right: I don’t see any particular reason to use pytz anymore for my applications.
I was actually going to title this, “A Brief and Incomplete Catalog of Static Site Search Options, None of Which You Will Love”, but I thought that would be too long.
This is a list of options I’ve found for adding search functionality to this web site, which is to say a small, statically-generated site that is a hobby and doesn’t produce any revenue. I mention that bit about no revenue because if this was more than just a personal site, and particularly if it were a site that makes money for me, I’d have no problem plunking down $40/month or so to get some kind of hosted search, or even just hosting something like Apache Solr myself.
I’m writing some software that interfaces with the GPIOs on a Raspberry Pi. I found myself wanting to test this software on my Mac while I was developing it, meaning I’d need to make “mock GPIO files” to test against. The trick was that I needed something I could send to
select(2) and signal an “exceptional condition,” since that’s how Linux indicates an interrupt on a GPIO. This ended up being an education for me on both TCP out-of-band data and, surprisingly, pseudo terminals.
Often enough, in Python, I find myself wanting to do something with a key’s value in a dictionary, but only if the key exists. I think that the most obvious way to write this is:
if key in some_dict: do_something_with(some_dict[key])
However, I always thought looking up the key in the dictionary twice was wasteful. Instead I preferred to write the following code, which remains readable but does only a single dictionary look up:
value = some_dict.get(key) if value is not None: do_something_with(value)
Surely one dictionary look up is faster than two!
Unfortunately I think my assumption was wrong.