Objects

Author

Jon Reades

Published

October 1, 2026

Overview

This week we will see how Python actually works by looking beyond simple functions and into methods, classes, and the outlines of Object Oriented Design and Programming (OOD/OOP). We’ll also look at what to do when ‘things go wrong’, because they will, but sometimes we want that to blow up the application while other times we want Python to handle the ‘exception’ gracefully. Learning to read Exceptions is essential to debugging code: the one thing that almost never works when you get an exception is ignoring it.

ImportantLearning Outcomes

By the end of this week you should be able to:

  1. Explain how classes, objects and methods relate, and create a simple class.
  2. Read a traceback, and use try/except to handle expected errors.
  3. Refactor inline code into functions and then into a simple package.
  4. Critique the idea of the data scientist as a neutral ‘expert’ (D’Ignazio & Klein ch. 5; Etherington).
NoteBefore class
  1. Watch the four pre-recorded lectures (≈ 50 min in total): Methods (5 min) · Classes (16 min) · Design (13 min) · Exceptions (16 min)
  2. Read D’Ignazio and Klein (2020a) and Etherington (2016), making notes against the study guide questions.
  3. Finalise your group: groups must be confirmed by the end of this week so that you can start work (use the signup form from last week’s session).
  4. Bring your laptop with Podman running. The last part of the practical, on classes, is optional.

This week deals with ‘objects’ and ‘classes’, which is fundamental to mastering the Python programming language: in Python, everything is an object, you just didn’t need to know it until now. Understanding how classes and objects work is essential to using Python effectively, but it will also make you a better programmer in any language because it will help you to think about how data and code work together to achieve your goals.

Readings

Come to class prepared to discuss the following readings:

Citation Article
D’Ignazio and Klein (2020a) Ch.5 URL
Etherington (2016) URL

Study Guide

  1. Reading D’Ignazio and Klein (2020a) (Ch.5) reflect on:
  • The authors of “Data Feminism” propose a shift from “data for good” to “data for co-liberation.” Explain the core differences between these two frameworks using examples from the sources.
  • Compare and contrast the data science methodologies employed by the Anti-Eviction Mapping Project (AEMP) and the Eviction Lab. How do their approaches to data collection, cleaning, and analysis reflect different values and priorities? What are the ethical implications of these choices, and how do they relate to the concept of “epistemic violence”?
  • The dominant metaphors used to describe data scientists, such as “unicorns,” “wizards,” and “rock stars,” can reinforce power imbalances in data work. Analyze the implications of these metaphors, and discuss how alternative framings of data science labor could promote more collaborative and equitable practices.
  1. Reading Etherington (2016) reflect on:
  • Why does Etherington advocate for teaching GIS programming to geographers using an open-source Python approach?
  • Describe the six core spatial concepts that Etherington uses to structure his GIS programming course and reflect on whether they improve our understanding of both. <!– 3. Reading Lansley (2016) reflect on:
  • Why does Lansley introduce a geography research article with an extensive review of marketing and advertising literature?
  • How does Lansley segment cars into distinctive categories and what are the implications of this segmentation for understanding the social and economic landscape of the UK?
  • What are some of the limitations of using administrative data, such as DVLA car registration data, to study socioeconomic trends? –>
  1. Collectively:
  • The sources highlight a tension between the need for “clean” data in analysis and the potential for data cleaning to obscure diversity. Consider specific examples from the sources that illustrate this tension, and analyze how different approaches to data cleaning might impact the representation of ‘outliers’ in the data (be they marginalised groups, or extreme values).
TipConnections

D’Ignazio and Klein (2020b, Ch.5) will hopefully help you to reorient your thoughts on what it is that data scientists do (are they rock stars or janitors or something else?), while Etherington (2016) will help you to see how spatial and programming concepts can be connected to one another to improve our understanding of both. For a particularly good example of this see the GIS Algorithms text (Xiao 2016).

We’re now going to shift our focus slightly towards more critical takes on data and data science. These are not by people who can’t ‘do’ data science, rather they point to ways in which neither the data, nor the people who process them, are neutral or objective in the way that we often like to think they are.

Pre-Recorded Lectures

Come to class having watched:

Session Video Presentation
Methods Video Slides
Classes Video Slides
Design Video Slides
Exceptions Video Slides

Practical

Warning

This practical will lead you through the process of converting inline scripts into functions and, ultimately, into a simple package. The last parts of the practical are optional – creating classes in hierarchies is integral to how Python works, but many data scientists will rarely need to write their own classes… they just make use of classes written by others (which is why understanding what they are is important, but being able to write your own is a little less so).

TipConnections

The practical focusses on:

  • Bedding in the ‘data thinking’ from last week’s practical.
  • Creating functions to perform repetitive tasks.
  • Packaging these functions up and accessing via the appropriate namespace.
  • Implementing a few simple classes so that you understand the basics of how they work.

To access the practical:

  1. Preview
  2. Download

References

D’Ignazio, Catherine, and Lauren F. Klein. 2020a. “Data Feminism.” In. MIT Press. https://data-feminism.mitpress.mit.edu/.
———. 2020b. Data Feminism. MIT Press. https://data-feminism.mitpress.mit.edu/.
Etherington, Thomas R. 2016. “Teaching introductory GIS programming to geographers using an open source Python approach.” Journal of Geography in Higher Education 40 (1). Taylor & Francis:117–30. https://doi.org/10.1080/03098265.2015.1086981.
Lansley, Guy. 2016. “Cars and Socio-Economics: Understanding Neighbourhood Variations in Car Characteristics from Administrative Data.” Regional Studies, Regional Science 3 (1). Taylor & Francis:264–85. https://doi.org/10.1080/21681376.2016.1177466.
Xiao, Ningchuan. 2016. GIS Algorithms: Theory and Applications for Geographic Information Science & Technology. Research Methods. SAGE. https://doi.org/https://dx.doi.org/10.4135/9781473921498.