Edinburgh Python Meetup August 2024
Python Meetup Edinburgh August 2024
On 2024-08-27 I was the opening speaker at the reboot of the Edinburgh Python Meetup. Thanks to Mark Smith’s team for masterminding the event and inviting me to such a delightful evening.
For me, starting out as a public speaker, this just the right size of event. About 40 people, some familiar faces, and a relaxed atmosphere. They warmed us with pizza and beer and general mingling in the open-plan kitchen for about 30 minutes before we all shuffled over to the seating and the projector to talk about snakes.
I had the honor of opening with What year was that? Dating music posters with Python.
My open-source work using Python in the AWS Community in theory gives me a lot to talk about, but to do it justice I wanted to more prep time than I was prepared to give myself in the last weeks of summer. This topic was simpler to prepare and a gentle opener that was well-received by Python newcomers and oldtimers alike. What follows is a bare-bones explanation of the solution. I’ll share more detail and insights from my research in a future blog post.
“Saturday 2nd August. What year was that?”
A Sunday afternoon WhatsApp rant from my Dad about the Creamfields 98 lineup inspired me to explore a modern answer to this question.
After a lot of Googling, a scan of a paper-based perpetual calendar helped him solve the problem. It’s a fine solution. A 200-year range fits on the back of a phone book, needs no electricity, and solves the problem with some linear lookups. But it’s tedious, and doesn’t get me invited to Python talks.
Can we solve the problem faster with today’s digital calendars? Almost. The user interface for repeating events is designed to solve problems such as “every Monday” or “every 4th Tuesday”. Google Calendar’s designer regrettably did not foresee my need to configure “Every Saturday 2nd of August”.
The underlying standard that enables calendar interoperability is the IETF’s iCalendar protocol. It’s easy to express using recurrence rule syntax:
RRULE:
FREQ=YEARLY;
BYDAY=SA;
BYMONTH=5;
BYMONTHDAY=2
And we can use the rrule
class from Python’s dateutil
module to evaluate it:
from datetime import date
from dateutil.rrule import rrule, YEARLY, SA
dads_birthyear=date(year=1954, month=1, day=1)
today=date.today()
creamfields_rule=rrule(
freq=YEARLY,
byweekday=SA,
bymonthday=2,
bymonth=5,
dtstart=dads_birthyear,
until=today,
)
print([match.year for match in creamfields_rule])
[1959, 1964, 1970, 1981, 1987, 1992, 1998, 2009, 2015, 2020]
You’ll always get a range of years. You need some cultural context to figure out which one it must be. A music festival attracts performers at the top of their game, so knowing when a band was big helps you to narrow it down.
Mark Smith followed to confess and apologize for Stupid Things I’ve Done With Python.
Mark has a folder on every computer called “stupid Python tricks”. It’s full of stuff that Python allows you to do, even if you probably shouldn’t.
Things like ish, which abuses the minus operator and Boolean values to make this code for testing “trueishness” into valid syntax:
if 'Yup' == True-ish:
print 'True-ish!'
The serious point he makes behind the fun and weird code is to understand Python’s Data Model.
Python implements the basic operators using specially named methods on objects (for example __sub__
for left-side subtraction and __rsub__
for right-side subtraction). As with all programming, a solid understanding of the fundamental concepts makes it easier to reason about the higher-level behavior, and easier to write expressive code.
Pathlib in the standard library overrides the division operator via __truediv__
and __rtruediv__
methods to allow path construction using syntax like this:
>>> Path("usr") / Path("local") / Path("bin")
PosixPath('usr/local/bin')
It inspired me to deepen my understanding of the Python language. I’m a confident Python hacker and have middling skills, but I struggle to explain what self
really is or what fundamentally defines an object. Mark promises that all the answers are in the data model doc, so add that to the reading list!
No one recorded us, but YouTube shows Mark delivering this talk elsewhere, most recently at PyCon Italia 2022.
Thanks to TrustPilot for hosting, TravelPerk for sponsoring the event, to Neil Miller for giving us a opening pep talk,and to Mar Doig for taking the photos!
After topping up on beer and pizza at TrustPilot HQ, we drifted into Milnes on Rose Street for some more pricey pints and joyously nerdy chatter. For me it was great way to reintegrate into Edinburgh’s tech scene.
Looking forward to monthly meetups going forward. September is already fully booked! Hope to see you there soon.