Prac00: Introduction to Linux


  • We will be using Linux as our operating system for this unit
  • You can access Linux through mydesktop.curtin.edu.au or install Python and a “Linux” shell on your home machine
  • Working on the command line, we will type in commands at the prompt, press enter, and wait for the computer’s response
  • To create and edit a text file, we will be using vim - a program for editing text files
  • Once we have entered a Python program as a text file, with a “.py” extension, we can run the program by typing python3 myprog.py

Prac01: Introduction to Python


  • We use input() to get the user’s input from the keyboard, and print() to output to the screen
  • To choose between parts of the code to run, we can use the if_elif_else control structure
  • If we want to repeat code, we can use for loops and while loops
  • while loops continue until a condition is false - we don’t know at the start how many times they will run
  • for loops repeat a set number of times, so we should use them when we know how many iterations we want
  • We can nest control strucures by indenting them inside each other

Prac02: Strings and Lists


  • The elements of a string are characters
  • We can access characters using their index
  • As we count from zero, the final element with be at length-1
  • There are many functions that we can use on strings, including upper(), lower() and count(). See the documentation at https://docs.python.org/3.11/library/stdtypes.html#text-sequence-type-str for more details
  • Strings and Lists are both sequences - order is important!
  • The elements of a list can be numbers, Booleans, strings or other lists
  • We can have lists of lists
  • As well as indexing elements, we can use slicing to access elements using [start:stop:step] notation.

Prac03: Arrays and Plotting


  • Arrays give compact storage and additional functionality when working with collections of data of the same type.
  • Arrays are implemented in the numpy package, which you import to be able to use them.
  • Plotting data aids understanding and helps us see trends.
  • We can plot using matplotlib. Other packages will be explored later in the semester

Prac04: 2-Dimensional Arrays, Functions and Plotting


  • Numpy provides multi-dimensional arrays in Python, along with useful functions and operations
  • Indexing and slicing are used in a similar way to other sequences (1-D arrays, strings and lists)
  • The Scipy library extends Numpy with more advanced functionality, including image processing. Images can be manipulated as Numpy arrays.
  • We can improve readibility and reduce repetition by defining and using functions.
  • Once a function has been tested - it can be used with confidence, which simplifies your code.
  • Functions can be grouped into modules and imported and reused in multiple programs

Prac05: Grids and Files


  • Files can provide persistent data that exists before and/or after our programs run? These files can also be used for sharing information, and allow more complex problems
  • We need to open files to have an object to represent the state of the files, and let us access input/output (I/O) functions. Files should be closed when we’ve finished reading/writing data.
  • Text files are strings, with three read functions - read(), readline(), readlines() and one write function - write()
  • See https://docs.python.org/3/tutorial/inputoutput.html#reading-and-writing-files for more about files
  • We can reduce the number of lines of code using list comprehensions - creating a new list from an
  • existing list/sequence + transformation + conditions.
  • Gridding algorithms allow us to use 2D+ arrays to create simulations - we just need to define how to calculate the next value in each cell on each timestep

Prac06: Modelling the World with Objects


  • We can model real world items as objects
  • The template for an object is its class - which we can use to make lots of objects
  • Objects know their state (data) and behaviour (methods) and are responsible for choosing who can access their data, and how… we can trust them to maintain a valid state
  • The convention is to use a capital letter for the class name, and lowercase for variables (which can hold objects)
  • If we create a dog object d1 = Dog("Brutus"), we call its methods as d1.sit() and can access data as d1.name or through a method e.g. d1.getName(). Accessing the data directly is often easier, but can be risky…
    1. Could alter data and make it invalid
    2. Requires knowledge of the internal workings of the object - which is against OO principles

Prac07: Object Relationships and Exception Handling


  • Classes are templates for creating objects
  • We can define classes to have objects contain other objects or inherit from a class heirarchy
  • We should define methods to allow communication with objects, and may have multiple levels of methods to work with collections and/or inheritance
  • Exception handling helps us make our code more robust by adding exception handling where errors might occur.

Prac08: Scripts and Automation


  • Our python programs so far have been applications working on data files
  • With scripting, we can also work with the operating system to create and move files, navigate the filesystem (ls, cd, mkdir etc.)
  • Using command line arguments lets us change parameters into a script/program - a bit like arguments into a function
  • Command line arguments help us make flexible code, avoiding entering data at prompts or editing files directly - both of which cna introduce errors
  • Using Unix utilities and our own programs as reusable steps in a workflow makes it possible to automate our processing

Prac09: Quality and Testing


  • There is a whole field, “Software Engineering”, that deals with ensuring software quality. We have touched on some of the areas involved so that you are aware of them.
  • Detailed coverage is beyond this unit, however, if you are involved in more complex software development in the future (client, team member, coder, tester) there are many resources available to support you.
  • In all of our coding, we should consider software quality and ways to test our code to be confident it performs as intended.
  • Tools that can support coding (version control, IDEs, co-pilot/genAI) can improve productivity and reduce risk of losing data/code
  • WARNING: you will always need to check back that the code/system you are developing matches the requirements - a perfect system that doesn’t solve the problem is worthless (actually it’s worse than that, as all the tme and money spent in development has been wasted).

Prac10: Applications: Data Processing and Analytics


  • Pandas is an easy to use packages for data analytics
  • It is built on dictionaries and concepts from sets
  • Sets and dictionaries can speed up some common tasks

Prac11: Applications: Engineering and Science


  • You are at a starting point for your career. Computational and data analytics skills will enhance your abiliaty to do your job, and to work in multidisiplinary teams.
  • Each domain will have it’s own preferred languages and environments.
  • Your foundational knowledge built in this unit can be transferred and expanded to match your chosen career.