Skip to content

Commit 34c56d2

Browse files
author
William Glass
committed
adding the actual custom_modules notebook...
1 parent 9f20a9d commit 34c56d2

1 file changed

Lines changed: 18 additions & 50 deletions

File tree

content/good_practice/custom_modules.ipynb

Lines changed: 18 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"cell_type": "markdown",
55
"metadata": {},
66
"source": [
7-
"# Packages"
7+
"# Custom Modules"
88
]
99
},
1010
{
@@ -16,7 +16,7 @@
1616
"* functions\n",
1717
"* types\n",
1818
"* collections\n",
19-
"* loops"
19+
"* packages"
2020
]
2121
},
2222
{
@@ -25,16 +25,21 @@
2525
"source": [
2626
"# Modules\n",
2727
"\n",
28-
"Before describing what a Python package is, we must first understand Python modules. We are now comfortable with writing simple Python code and may now want to write our first dedicated program. But what is the best way to set out our code? One of the key concepts in programming is the creation of simple and easy to maintain code, this is where modules come in. \n",
29-
"\n",
30-
"Instead of creating one large piece of code that can often be unwieldy we can break it up into smaller chunks, or modules. Each module has a specific functionality that allows it to be reused without the need for duplicating code."
28+
"Instead of creating one large piece of code that can often be unwieldy we can break it up into smaller chunks, or modules. Modules can be accessed through installed packages or they can written by the user. "
29+
]
30+
},
31+
{
32+
"cell_type": "markdown",
33+
"metadata": {},
34+
"source": [
35+
"## Custom Modules"
3136
]
3237
},
3338
{
3439
"cell_type": "markdown",
3540
"metadata": {},
3641
"source": [
37-
"Below is an example module called `print_things.py`:"
42+
"Below is an example of a custom module (i.e. one we have writeen ourselves) called `print_things.py`:"
3843
]
3944
},
4045
{
@@ -100,15 +105,9 @@
100105
},
101106
{
102107
"cell_type": "code",
103-
"execution_count": 1,
108+
"execution_count": null,
104109
"metadata": {},
105-
"outputs": [
106-
{
107-
"output_type": "stream",
108-
"name": "stdout",
109-
"text": "Hydrogen\nHelium\nLithium\nKey: Hydrogen, Value: 1\nKey: Helium, Value: 2\nKey: Lithium, Value: 3\n"
110-
}
111-
],
110+
"outputs": [],
112111
"source": [
113112
"import print_things\n",
114113
"\n",
@@ -121,13 +120,6 @@
121120
"print_things.print_dictionary(element_protons)"
122121
]
123122
},
124-
{
125-
"cell_type": "markdown",
126-
"metadata": {},
127-
"source": [
128-
"### Using `from`"
129-
]
130-
},
131123
{
132124
"cell_type": "markdown",
133125
"metadata": {},
@@ -137,15 +129,9 @@
137129
},
138130
{
139131
"cell_type": "code",
140-
"execution_count": 2,
132+
"execution_count": null,
141133
"metadata": {},
142-
"outputs": [
143-
{
144-
"output_type": "stream",
145-
"name": "stdout",
146-
"text": "Hydrogen\nHelium\nLithium\n"
147-
}
148-
],
134+
"outputs": [],
149135
"source": [
150136
"from print_things import print_names\n",
151137
"\n",
@@ -170,16 +156,16 @@
170156
"Another useful way to use both the `import` / `from` statements is to `import` modules and use an alternative name:\n",
171157
"\n",
172158
"```python\n",
173-
"from print_things import print_names as pn # import print_names from the print_things module \n",
174-
"import print_things as pt # import the whole print_things module\n",
159+
"from print_things import print_names as pn # Import print_names from the print_things module \n",
160+
"import print_things as pt # Import the whole print_things module\n",
175161
"``` "
176162
]
177163
},
178164
{
179165
"cell_type": "markdown",
180166
"metadata": {},
181167
"source": [
182-
"# Packages"
168+
"## Organising Modules: Packages"
183169
]
184170
},
185171
{
@@ -221,24 +207,6 @@
221207
"\n",
222208
"Luckily we usually don't need to worry about where packages are as we can use a dedicated package manager to automatically take care of their location for us. These managers are useful and contain a huge variety of different packages that aren't included within Python as standard. For example, packages such as `NumPy` are commonly retrieved this way. \n"
223209
]
224-
},
225-
{
226-
"cell_type": "markdown",
227-
"metadata": {},
228-
"source": [
229-
"# Python Package Managers"
230-
]
231-
},
232-
{
233-
"cell_type": "markdown",
234-
"metadata": {},
235-
"source": [
236-
"TODO\n",
237-
"\n",
238-
"pip\n",
239-
"\n",
240-
"conda\n"
241-
]
242210
}
243211
],
244212
"metadata": {

0 commit comments

Comments
 (0)