Skip to content

Commit 9d8bb54

Browse files
committedAug 18, 2022
feat(task read all lines): added a new task
1 parent 88b6066 commit 9d8bb54

File tree

8 files changed

+46
-0
lines changed

8 files changed

+46
-0
lines changed
 

‎File input output/Read all lines/__init__.py

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
The plates will still shift
2+
and the clouds will still spew.
3+
The sun will slowly rise
4+
and the moon will follow too.
5+
(By Amy O. Connor)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
type: edu
2+
files:
3+
- name: task.py
4+
visible: true
5+
placeholders:
6+
- offset: 43
7+
length: 31
8+
placeholder_text: '# TODO: read all lines from input.txt into the list called
9+
lines_list'
10+
- name: tests/test_task.py
11+
visible: false
12+
- name: __init__.py
13+
visible: false
14+
- name: tests/__init__.py
15+
visible: false
16+
- name: input.txt
17+
visible: true
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
## Read all lines
2+
3+
### Task
4+
Read all lines from the file input.txt into the list called `lines_list`. There are at least two different ways to do it.
5+
6+
<div class="hint">Two possible solutions are discussed in the previous task.</div>
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
with open("input.txt", "r") as infile:
2+
lines_list = infile.readlines()
3+
4+
if __name__ == "__main__":
5+
print(lines_list)

‎File input output/Read all lines/tests/__init__.py

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import contextlib
2+
import io
3+
import unittest
4+
5+
from task import lines_list
6+
7+
8+
class TestCase(unittest.TestCase):
9+
def test_out(self):
10+
with open("input.txt", "r") as f:
11+
expected_list = f.readlines()
12+
self.assertEqual(expected_list, lines_list, msg="lines_list does not match the expected list.")

‎File input output/lesson-info.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ custom_name: File input/output
22
content:
33
- Open file
44
- Read file
5+
- Read all lines
56
- Write to file
67
- What next

0 commit comments

Comments
 (0)
Please sign in to comment.