-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
richelbilderbeek
committed
Jan 15, 2024
1 parent
e95fd0b
commit 833f325
Showing
3 changed files
with
130 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters