Skip to content

Commit

Permalink
Start file IO
Browse files Browse the repository at this point in the history
  • Loading branch information
richelbilderbeek committed Jan 15, 2024
1 parent e95fd0b commit 833f325
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 10 deletions.
101 changes: 101 additions & 0 deletions docs/afternoon_session/files.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# Files

!!!- info "Learning objectives"

- Have read a file
- Have created a file

???- question "For teachers"

Teaching goals are:

* Learners have read a file
* Learners have created a file

Lesson plan:

* 5 mins: prior knowledge
* 5 mins: presentation
* 15 mins: challenge
* 5 mins: feedback

## Overview

Most programmers need to work on data and produce some result.
In Python, we -of course- can read from files and write to files.
Here we do just that.

## Exercises

### Exercise 1: create a simple text file

!!!- info "Learning objectives"

- Create a simple text file

Read the following sections of [How to Think Like a Computer Scientist: Learning with Python 3](https://openbookproject.net/thinkcs/python/english3e/index.html):

- 13.1. About files
- 13.2. Writing our first file

Then do:

- Put the code at the top of 13.2 in a Python script
- Run that code
- Verify that it works as expected


### Exercise 2: create a simple text file


!!!- info "Learning objectives"

- Read a simple text file
- Repeat creating a file
- Practice to search the internet how to reverse the order of text lines

Read the following sections of [How to Think Like a Computer Scientist: Learning with Python 3](https://openbookproject.net/thinkcs/python/english3e/index.html):

- 13.4. Turning a file into a list of lines

Consider searching for ['Python reverse order'](https://lmddgtfy.net/?q=python%20reverse%20order),
as you will need to do this in the exercise.

Then do:

- Exercise 13.11.1


### Exercise 3: working with an input file

!!!- info "Learning objectives"

- Import a Python package
- Practice to search for an UPPMAX module that needs to be loaded
- Get a script that requires an UPPMAX module to be loaded to work

Now we try to make this script work!

Read:

- [the UPPMAX documentation 'Loading Python packages'](http://docs.uppmax.uu.se/software/python/#loading-python-packages)
- [the UPPMAX documentation 'Modules'](http://docs.uppmax.uu.se/cluster_guides/modules/)

Now, try to get the script to work.

When running the code, there should be a visible pop-up window. If not,
re-read [the UPPMAX documentation page 'Login to Rackham'](http://docs.uppmax.uu.se/getting_started/login_rackham/)
and enable X-forwarding.

???- question "Need more hints?"

The exercise is about *practicing* to search for an UPPMAX module,
hence giving away the answer makes this session useless.

However, if you feel stuck too much,
you can watch a video in which this exercise is done
[here](https://youtu.be/bnN-1uzsgvk)

## Links

* [How to Think Like a Computer Scientist: Learning with Python 3](https://openbookproject.net/thinkcs/python/english3e/index.html)
31 changes: 25 additions & 6 deletions docs/afternoon_session/hello_little_turtles.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,35 @@

!!!- info "Learning objectives"

- Import a Python package
- Have a first 'Get stuff to work' experience
- Rehearse creating a script
- Experience when importing a Python package gives an error
- Search for an UPPMAX module that needs to be loaded
- Run a script that requires an UPPMAX module to be loaded
- Import a Python package successfully

???- question "For teachers"

Teaching goals are:

* .
* Learners have observed the error when importing a Python package without the needed UPPMAX module loaded
* Learners have search through the UPPMAX modules
* Learners may find out that X-forwarding is important
* Learners have gotten 'stuff to work'

Lesson plan:

* 5 mins: prior knowledge
* 5 mins: presentation
* 15 mins: challenge
* 25 mins: challenge
* 5 mins: feedback

## Overview

Sometime you need to get 'stuff to work', for example,
code written by someone else.
In this session, we practice this,
going through the problems and errors that occur
when you want to 'just want to run the stupid code'.

## Exercises

Expand All @@ -45,8 +55,8 @@ Run the script and verify it will not run. Does the error message make sense?
!!!- info "Learning objectives"

- Import a Python package
- Search for an UPPMAX module that needs to be loaded
- Run a script that requires an UPPMAX module to be loaded
- Practice to search for an UPPMAX module that needs to be loaded
- Get a script that requires an UPPMAX module to be loaded to work

Now we try to make this script work!

Expand All @@ -61,6 +71,15 @@ When running the code, there should be a visible pop-up window. If not,
re-read [the UPPMAX documentation page 'Login to Rackham'](http://docs.uppmax.uu.se/getting_started/login_rackham/)
and enable X-forwarding.

???- question "Need more hints?"

The exercise is about *practicing* to search for an UPPMAX module,
hence giving away the answer makes this session useless.

However, if you feel stuck too much,
you can watch a video in which this exercise is done
[here](https://youtu.be/bnN-1uzsgvk)

## Links

* [How to Think Like a Computer Scientist: Learning with Python 3](https://openbookproject.net/thinkcs/python/english3e/index.html)
8 changes: 4 additions & 4 deletions docs/afternoon_session/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@ This module introduces the fundamentals of Python programming language.
* :check: How to work with basic builtin data types
* :check: How to create and run a Python script
* How to use UPPMAX modules to load a Python package
* How to creating a command line program that can take input arguments
* How to reading files
* How to writing to files
* How to creating a command line program that can take input arguments
* How to use control flow statements
* How to bundle code into reusable functions

## Schedule

| Time | Topic |
|---------------|-------------------------------|
| 13:00-14:00 | Functions and Modules |
| 13:00-14:00 | [UPPMAX modules and Python packages](hello_little_turtles.md)
| 14:00-14:15 | Break |
| 14:15-15:00 | Command line arguments and IO |
| 14:15-15:00 | [File IO](files.md) |
| 15:00-15:15 | Break |
| 15:15-16:00 | Exercises |
| 15:15-16:00 | Command line arguments, functions |

Link to HackMd: <https://hackmd.io/@dianai/uppmax-intro/>

Expand Down

0 comments on commit 833f325

Please sign in to comment.