Skip to content

Commit 255482b

Browse files
authored
new
1 parent 4d5e449 commit 255482b

4 files changed

Lines changed: 125 additions & 0 deletions

File tree

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
---
2+
3+
1.3.5 SECTION QUIZ
4+
5+
---
6+
7+
**Question 1:** You want to prevent your module's user from running your code as an ordinary script. How will you achieve such an effect?
8+
9+
<details>
10+
<summary>Check</summary>
11+
12+
```
13+
import sys
14+
15+
if __name__ == "__main__":
16+
print "Don't do that!"
17+
sys.exit()
18+
```
19+
</details>
20+
21+
---
22+
23+
**Question 2:** Some additional and necessary packages are stored inside the <code>D:\Python\Project\Modules</code> directory. Write a code ensuring that the directory is traversed by Python in order to find all requested modules.
24+
25+
```
26+
import sys
27+
28+
# note the double backslashes!
29+
sys.path.append("D:\\Python\\Project\\Modules")
30+
31+
```
32+
33+
Assuming that <code>D:\Python\Project\Modules</code> has been successfully appended to the `sys.path` list, write an import directive letting you use all the `mymodule` entities.
34+
35+
<details>
36+
<summary>Check</summary>
37+
38+
```
39+
import sys
40+
41+
# note the double backslashes!
42+
sys.path.append("D:\\Python\\Project\\Modules")
43+
```
44+
</details>
45+
46+
---
47+
48+
**Question 3:** The directory mentioned in the previous exercise contains a sub-tree of the following structure:
49+
50+
```
51+
abc
52+
|__ def
53+
|__ mymodule.py
54+
55+
```
56+
57+
<details>
58+
<summary>Check</summary>
59+
60+
```
61+
import abc.def.mymodule
62+
```
63+
</details>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
1. ```python
2+
if '__name__' == '__main__':
3+
print("This script shouldn't be run directly!")
4+
exit()
5+
```
6+
- This is wrong because `__name__` is a variable.
7+
- Is it needed to import `sys.exit()` here? What's the difference?
8+
2. ```python
9+
import sys
10+
11+
sys.path.append("D:\\Python\\Project\\Modules")
12+
```
13+
14+
3. ```import abc.def.mymodule```
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
3+
1.4.9 SECTION QUIZ
4+
5+
---
6+
7+
**Question 1:** Where does the name "The Cheese Shop" come from?
8+
9+
<details>
10+
<summary>Check</summary>
11+
12+
It's a reference to an old Monty Python's sketch of the same name.
13+
</details>
14+
15+
---
16+
17+
**Question 2:** Why should I ensure which one of _pip_ and _pip3_ works for me?
18+
19+
<details>
20+
<summary>Check</summary>
21+
22+
When Python 2 and Python 3 coexist in your OS, it's likely that _pip_ identifies the instance of _pip_ working with Python 2 packages only.
23+
</details>
24+
25+
---
26+
27+
**Question 3:** How can I determine if my _pip_ works with either Python 2 or Python 3?
28+
29+
<details>
30+
<summary>Check</summary>
31+
32+
`pip --version` will tell you that.
33+
</details>
34+
35+
---
36+
37+
**Question 4:** Unfortunately, I don't have administrative right. What should I do to install a package system-wide?
38+
39+
<details>
40+
<summary>Check</summary>
41+
42+
You have to ask your _sysadmin_ - don't try to hack your OS!
43+
44+
</details>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
1. Monty Python
2+
2. IDK > When Python 2 and Python 3 coexist in your OS, it's likely that *pip* identifies the instance of *pip* working with Python 2 packages only.
3+
3. IDK > Use `pip --version` to check compatibility with other Python versions
4+
4. Raise that situation to the IT department

0 commit comments

Comments
 (0)