Today I learned that Python has nested Easter eggs in the standard library.
If you open the Python REPL and type import antigravity
or if you put that in a script and then run it, Python will open your browser and take you to https://xkcd.com/353/, where you can find the following comic:
According to a blog article by Guido van Rossum, this was added to Python 3 as an Easter egg after the comic was created, which is quite cool if you think about it.
Randall Munroe, the author of the comic, joked about Python and his joke ended up materialising as a module.
But then, if you inspect the source code for the module antigravity
in Python 3.13, you will find another Easter egg:
import webbrowser
import hashlib
webbrowser.open("https://xkcd.com/353/")
def geohash(latitude, longitude, datedow):
'''Compute geohash() using the Munroe algorithm.
>>> geohash(37.421542, -122.085589, b'2005-05-26-10458.68')
37.857713 -122.544543
'''
# https://xkcd.com/426/
h = hashlib.md5(datedow, usedforsecurity=False).hexdigest()
p, q = [('%f' % float.fromhex('0.' + x)) for x in (h[:16], h[16:32])]
print('%d%s %d%s' % (latitude, p[1:], longitude, q[1:]))
The only function defined in that module is yet another reference to another xkcd comic, this time comic 426:
I can't help but smile when I think about the fact that Python, a language used by so many corporations and that plays such an important role in our lives – whether we understand that or not — apparently has a sense of humour.
+35 chapters. +400 pages. Hundreds of examples. Over 30,000 readers!
My book “Pydon'ts” teaches you how to write elegant, expressive, and Pythonic code, to help you become a better developer. >>> Download it here 🐍🚀.