You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: your-turn/11-python-packages/readme.md
+5-6Lines changed: 5 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -44,21 +44,21 @@ Notice it created the empty `__init__.py` for you and the folder icon is slightl
44
44
45
45
## Add a feature
46
46
47
-
We'll add a couple of simple math methods to our calculator. Create another Python file in the folder called `math.py` and add an `add(x, y)` and `subtract(x, y)` pair of methods to `math.py`.
47
+
We'll add a couple of simple math methods to our calculator. **Create another Python file** in the folder called `math.py` and add an `add(x, y)` and `subtract(x, y)` pair of methods to `math.py`.
48
48
49
49
To make importing it easier, add this line to `__init__.py`:
50
50
51
51
```python
52
52
from . import math
53
53
```
54
54
55
-
That means you can consume it by typing `import calcy` then calling `calcy.math.add(7, 11)`.
55
+
That means you can consume it by typing `import calcy` then calling `calcy.math.add(7, 11)`. If you omit this, you'll have to type `import calcy.math` to use the library like this even if you have already typed `impot calcy`.
56
56
57
57
Use the Python Console in PyCharm to test this (it adds the necessary path adjustments to run the package). For example, when I run the Python console, I see this output prior to the `>>>` prompt.
58
58
59
59
```python
60
60
import sys; print('Python %s on %s'% (sys.version, sys.platform))
This is PyCharm automatically extending the Python path. You do **not** need to do anything to make this happen. It's just PyCharm making life easy on us.
@@ -67,13 +67,12 @@ Now, in the console, here's one way to test it:
67
67
68
68
```python
69
69
import calcy
70
-
calcy.math.add(7, 5)
71
-
12
70
+
calcy.math.add(7, 5) # <-- outputs 12
72
71
```
73
72
74
73
In this special environment, it should work.
75
74
76
-
## Include a setup
75
+
## Include a pyproject.toml
77
76
78
77
It's great you can run your code locally. But for real packages, you'll need to be able to install it for consumers. To do this, we need a `setup.py`.
0 commit comments