Chalmers Advanced Python

Exercise 01: Getting started

Advanced Python Course
Chalmers DAT690 / DIT516 / DAT516
2026

by John J. Camilleri & Muhammad Mustafa Hassan

Purpose

The purpose of this lab is to get you up and running with everything you need to start working on Labs 1–3. This exercise targets learning objectives:

1. Python development environment

Firstly, it is essential that you have a working Python installation on your computer, together with a text editor or IDE such as VS Code. You also need to have some familiarity with your computer’s terminal/shell.

Hopefully you already have these from a previous course. Note that web-based solutions like the Self Practice tool or Jupyter Notebook will not be enough.

Before progressing to the next step, ensure that you can:

  1. Create, edit and save a “hello world” Python file on your computer with filename hello.py.
  2. Run this Python file from your IDE, e.g. by clicking the ▶ button in VS Code.
  3. Run this Python file from your terminal, e.g. by running python3 hello.py.

2. Virtual environments

In this course we are going to be installing and using external Python libraries. In order to be able to do this, you need to be familiar with how to set up virtual environments.

The general idea is that each project has its own virtual environment into which packages are installed. See the instructions in the lecture notes here: Packages and virtual environments

Before progressing to the next step, ensure that you can:

  1. Create a Python virtual environment and activate it.
  2. Install the external library rich into your virtual environment with pip install rich.
  3. Import this library in your own code and use it, e.g. with this code snippet:

     from rich import print
     print("Hello, [bold green]World[/bold green]!", ":snake:")
    

3. Git

The Git version control tool will be used throughout this course for:

It is therefore important to get the hang of Git early on. To complete this step, do the following:

  1. Familiarise yourself with Git by reading the walkthrough in the lecture notes: Introduction to Git
  2. Set up an SSH key and ensure you have Git installed: Setting up SSH and Git
  3. Access Chalmers GitLab as described here: Working with Chalmers GitLab
  4. Create a repository:
    1. Create a new repository in GitLab: https://git.chalmers.se/projects/new#blank_project. Choose “Blank Project”.
    2. Copy the repository’s SSH URL, something like git@git.chalmers.se:username/my-repo.git
    3. Clone the repository locally, using git clone git@git.chalmers.se:username/my-repo.git on the command line or directly inside of VS Code.
    4. You should see an automatically-generated file README.md.
  5. Commit some changes:
    1. Change the contents of your local copy of the README.md file.
    2. Stage the changes to the file and create a new commit, giving it a descriptive message such as “Update README”.
    3. Push your commit to GitLab.
    4. View your repository on GitLab and ensure that file has been updated there. The URL will be something like: https://git.chalmers.se/username/my-repo
  6. Create a merge request:
    1. Create a new branch locally and check it out, e.g. with git checkout -b my-new-branch
    2. Add the hello.py file created previously to the repository, and write something about it in README.md.
    3. Commit these changes to the new branch and push them to GitLab.
    4. From GitLab, create a merge request from this new branch into the main branch.
  7. Review the merge request:
    1. View the merge request in GitLab, examine the diff and leave a comment on it.
    2. Push additional commits to the same branch, and see that the merge request is updated.
    3. Merge the merge request in GitLab.
  8. Update your local repository:
    1. Locally, change back to main branch with git checkout main. The changes you made in the new branch will appear to have been undone.
    2. Pull from GitLab with git pull and you should see that the latest changes have also been updated in the main branch.