GAMR1520: Markup languages and scripting

python logo

Week 2: Files, functions and classes

Back to home

With a good understanding of the basics we can move on to loading complex data into memory for processing. This week we will play with some data and learn how to read and write data directly from/to files in common JSON and CSV file formats. We will then go on to create some more structured code using functions and classes.

Lectures

Lecture 2.1: Working with files

Python is extremely good at data processing and reading and writing to files in various formats. This lecture covers the basic of file IO in python and introduces the pathlib, CSV and JSON modules from the standard library.

Lecture 2.2: Object oriented python

An introduction to object-oriented python. This lecture covers the basics of what a class is and how to define your own types in python. It maps pretty much directly onto lab exercise 2.3.

Lab exercises

Lab 2.1: Files and folders

In this set of exercises we will explore how to use python to save data to the filesystem and load it back again.

Lab 2.3: Object-oriented python

This exercise introduces object-oriented programming in python. We will develop very simple classes and explore the complexities and benefits of this approach.

Other resources