Python

Lab 3 Test Driven Development

Aims The aim of this lab is to introduce pytest and the process of Test Driven Development, we will do this in the following way. Use uv to set up a pytest Python environment. Write unit tests with pytest. Incrementally build a Vec3 class (3D vector math) following TDD. Getting started We place all our code in a simple project folder with the tests and the class we wish to test. In this case we are building a simple example, typically we would generate a python module or package as we will see in later lectures.

Lab 4 OO in Python

Aims The aim of this lab is to investigate Object Orientation in python The principles of S.O.L.I.D Classes in Python OO Design principles SOLID Is A mnemonic to remember the first five principles of Object Oriented design

Lab 4 An Image Class

Aims The aim of this lab is to continue our exploration of TDD in python by developing an Image Class Configure GitHub for labs. Developing a Simple Image Class Understand and Use python packages and uv Develop some simple Image algorithms. Getting Started We are now going to create a new labs folder based on our GitHub classroom (you would have been sent an invite). First we are going to enable GitHub over ssh via this method

Lab 5 Test Driven Development

Aims The aim of this lab is to introduce the process of test driven development (TDD) and develop some simple tests, we will use the following steps. Project Setup Version Control Setup Test Setup Test Driven Design of a Simple RGBA class Storing Pixels It is common to store image pixel data using a single unsigned int32_t data type. In C/C++ this is quite simple, however in python these things are a little harder as we don’t have the same data types. For our example we are going to use a single integer value called pixel to store our RGBA values but we will need to encode them using some logic.

Computational Thinking

What is Computational Thinking? The idea of computational thinking is allow us to look at problems and determine the best way for a computer to solve this (and related problems). This is basically a way of re-framing the problem / domain so it can be computationally processed.

Computational Thinking

What is Computational Thinking? The idea of computational thinking is allow us to look at problems and determine the best way for a computer to solve this (and related problems). This is basically a way of re-framing the problem / domain so it can be computationally processed.

Simple Programs

Simple Programs with Python In this session we will look at writing some simple stand alone programs in Python. We will cover the following topics: #!/ __main__ sys.argv The first thing to note is that Python is an interpreted language, this means that you can run Python code directly from the command line. This is done by typing python followed by the name of the file containing the Python code. For example to run a file called hello.py you would type:

Setup Python for Machine Learning and AI

Introduction In Lab1 we introduced the PyEnv tool to allow us to install various versions of python either locally or globally. In the following examples we will explore how we can setup and install specific ML libraries into a Virtual Environment using the global PyEnv python.

Databases and SQL

Databases and SQL

Command Line Arguments

Overview In this session we will look at how to pass arguments to a Python program from the command line. We will cover the following topics: sys.argv argparse click What are command line arguments? Command line arguments are values that are passed to a program when it is run from the command line. These values can be used to control the behavior of the program, for example by specifying input files, output files, or other options.