Skip to content

Commit 1396208

Browse files
authored
Merge pull request #233 from jetbrains-academy/konstantin/modules_feedback_improvements
Improvements of Modules lesson according to feedback
2 parents 49cc31c + d6b1bad commit 1396208

File tree

21 files changed

+123
-76
lines changed

21 files changed

+123
-76
lines changed

Modules and packages/Built-in modules/task.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ secondary prompts if the interpreter is in the interactive mode:
2020
The variable `sys.path` is a list of strings that determines the interpreter’s search path
2121
for modules: see what it prints for you when you run the code of the task.
2222

23-
Remember that you can use &shortcut:CodeCompletion; after a dot (.) to explore available
23+
Remember that you can use the &shortcut:CodeCompletion; shortcut after a dot (.) to explore available
2424
methods of a module. You can read more about standard modules <a href="https://docs.python.org/3/tutorial/modules.html#standard-modules">here</a>.
2525

2626
For more structured and detailed information, you can also refer to [this Hyperskill knowledge base page](https://hyperskill.org/learn/step/6019#built-in-modules?utm_source=jba&utm_medium=jba_courses_links).

Modules and packages/From import/task-info.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
type: edu
22
files:
3-
- name: my_module.py
4-
visible: true
5-
- name: calculator.py
6-
visible: true
73
- name: from_import.py
84
visible: true
95
placeholders:
@@ -13,6 +9,10 @@ files:
139
- offset: 97
1410
length: 12
1511
placeholder_text: '''Instantiate a calculator'''
12+
- name: my_module.py
13+
visible: true
14+
- name: calculator.py
15+
visible: true
1616
- name: tests/__init__.py
1717
visible: false
1818
- name: tests/test_task.py

Modules and packages/Import module/task-info.yaml

Lines changed: 0 additions & 23 deletions
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import my_funcs
2+
3+
my_funcs.hello_world("John")
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
type: edu
2+
custom_name: Import module
3+
files:
4+
- name: imports.py
5+
visible: true
6+
placeholders:
7+
- offset: 26
8+
length: 19
9+
placeholder_text: '# call the hello_world function from the my_funcs module'
10+
- name: my_funcs.py
11+
visible: true
12+
- name: tests/__init__.py
13+
visible: false
14+
- name: tests/test_task.py
15+
visible: false
16+
feedback_link: https://docs.google.com/forms/d/e/1FAIpQLSfRlDlldKfuq-cHMNFfHMER61P1PRIan7KG6yp1GvaweDI7GA/viewform?usp=pp_url&entry.2103429047=Modules+and+Packages+/+Import+module

Modules and packages/Import module/task.md renamed to Modules and packages/Import_module/task.md

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,13 @@ directly, but using the module name, you can now access the functions, for examp
1616
```python
1717
my_funcs.func1()
1818
```
19-
20-
Modules can import other modules. It is customary but not required to place all
21-
import statements at the beginning of a module.
22-
23-
You can find out more about modules in Python by reading [this section](https://docs.python.org/3/tutorial/modules.html) of The Python Tutorial.
2419

2520
For more structured and detailed information, you can also refer to [this Hyperskill knowledge base page](https://hyperskill.org/learn/step/6019#module-loading?utm_source=jba&utm_medium=jba_courses_links).
2621

2722
### Task
28-
In the code editor, import the module `calculator` and create an instance of the class `Calculator` (`calc`).
29-
Use the `add` method defined in `Calculator` in a loop to add up numbers from 0 to 99.
23+
In the code editor, you have already imported the module `my_funcs`.
24+
Call the function `hello_world` from this module with the argument `"John"`.
3025

31-
<div class='hint'>Use the <code>import</code> keyword and the <code>calculator</code> reference.</div>
3226
<div class='hint'>Access the function from the module using syntax such as <code>module.function()</code>.</div>
3327
<div class="hint">Don't forget to provide the function with an argument.</div>
3428

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import unittest
2+
import contextlib
3+
import io
4+
import re
5+
6+
f = io.StringIO()
7+
try:
8+
with contextlib.redirect_stdout(f):
9+
from imports import *
10+
output = f.getvalue().split('\n')
11+
12+
class TestCase(unittest.TestCase):
13+
def test_out(self):
14+
expected, actual = 'Hello, World! My name is John', output[0]
15+
self.assertEqual(expected, actual, msg='Call hello_world with the "John" argument.')
16+
17+
except AttributeError:
18+
class TestFailCase(unittest.TestCase):
19+
def test_fail(self):
20+
self.assertTrue(False, msg='You need to use the hello_world function from the my_funcs module.')

0 commit comments

Comments
 (0)