Skip to content

Commit 743d2dd

Browse files
committed
Tweek slides.
1 parent f96ba01 commit 743d2dd

File tree

1 file changed

+81
-71
lines changed

1 file changed

+81
-71
lines changed

slides.ipynb

+81-71
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"## Scott Overholser\n",
1515
"<br/>\n",
1616
"<br/>\n",
17-
"## https://github.com/eigenholser\n"
17+
"## https://github.com/eigenholser/python-magic-methods\n"
1818
]
1919
},
2020
{
@@ -58,14 +58,48 @@
5858
}
5959
},
6060
"source": [
61-
"# Python objects"
61+
"# Magic Methods"
62+
]
63+
},
64+
{
65+
"cell_type": "markdown",
66+
"metadata": {
67+
"slideshow": {
68+
"slide_type": "fragment"
69+
}
70+
},
71+
"source": [
72+
"* Beautiful, intuitive, and standard ways of performing basic operations."
73+
]
74+
},
75+
{
76+
"cell_type": "markdown",
77+
"metadata": {
78+
"slideshow": {
79+
"slide_type": "fragment"
80+
}
81+
},
82+
"source": [
83+
"* Define meaning for operators so that we can use them on our own classes like they were built in types."
84+
]
85+
},
86+
{
87+
"cell_type": "markdown",
88+
"metadata": {
89+
"slideshow": {
90+
"slide_type": "subslide"
91+
}
92+
},
93+
"source": [
94+
"# Python Built-in Types"
6295
]
6396
},
6497
{
6598
"cell_type": "code",
6699
"execution_count": null,
67100
"metadata": {
68101
"collapsed": false,
102+
"scrolled": true,
69103
"slideshow": {
70104
"slide_type": "fragment"
71105
}
@@ -129,7 +163,7 @@
129163
},
130164
"outputs": [],
131165
"source": [
132-
"(2).__pow__(3)"
166+
"(2).__pow__(3) "
133167
]
134168
},
135169
{
@@ -150,7 +184,7 @@
150184
"cell_type": "markdown",
151185
"metadata": {
152186
"slideshow": {
153-
"slide_type": "slide"
187+
"slide_type": "subslide"
154188
}
155189
},
156190
"source": [
@@ -165,7 +199,7 @@
165199
}
166200
},
167201
"source": [
168-
"* We can add magic methods to objects that we create."
202+
"* We can add magic methods to make our own objects behave like built-in types."
169203
]
170204
},
171205
{
@@ -187,32 +221,18 @@
187221
}
188222
},
189223
"source": [
190-
"* Expressiveness"
224+
"* Expressiveness!"
191225
]
192226
},
193227
{
194228
"cell_type": "markdown",
195229
"metadata": {
196-
"slideshow": {
197-
"slide_type": "subslide"
198-
}
199-
},
200-
"source": [
201-
"## The Zen of Python"
202-
]
203-
},
204-
{
205-
"cell_type": "code",
206-
"execution_count": null,
207-
"metadata": {
208-
"collapsed": false,
209230
"slideshow": {
210231
"slide_type": "fragment"
211232
}
212233
},
213-
"outputs": [],
214234
"source": [
215-
"import this"
235+
"* ...and it's zen."
216236
]
217237
},
218238
{
@@ -223,29 +243,21 @@
223243
}
224244
},
225245
"source": [
226-
"# Magic Methods"
227-
]
228-
},
229-
{
230-
"cell_type": "markdown",
231-
"metadata": {
232-
"slideshow": {
233-
"slide_type": "fragment"
234-
}
235-
},
236-
"source": [
237-
"* Beautiful, intuitive, and standard ways of performing basic operations."
246+
"## The Zen of Python"
238247
]
239248
},
240249
{
241-
"cell_type": "markdown",
250+
"cell_type": "code",
251+
"execution_count": null,
242252
"metadata": {
253+
"collapsed": false,
243254
"slideshow": {
244255
"slide_type": "fragment"
245256
}
246257
},
258+
"outputs": [],
247259
"source": [
248-
"* Define meaning for operators so that we can use them on our own classes like they were built in types."
260+
"import this"
249261
]
250262
},
251263
{
@@ -312,18 +324,20 @@
312324
},
313325
"outputs": [],
314326
"source": [
315-
"CAN, JFK, LAX, SLC"
327+
"CAN, JFK, LAX, SLC\n"
316328
]
317329
},
318330
{
319331
"cell_type": "markdown",
320332
"metadata": {
321333
"slideshow": {
322-
"slide_type": "subslide"
334+
"slide_type": "slide"
323335
}
324336
},
325337
"source": [
326-
"## Instantiate some objects"
338+
"# Object Construction\n",
339+
"\n",
340+
"* The `__init__(self, [args...])` magic method."
327341
]
328342
},
329343
{
@@ -360,31 +374,9 @@
360374
}
361375
},
362376
"source": [
363-
"# `__init__()`"
364-
]
365-
},
366-
{
367-
"cell_type": "markdown",
368-
"metadata": {
369-
"slideshow": {
370-
"slide_type": "fragment"
371-
}
372-
},
373-
"source": [
374-
"# TODO: `__init__()` stuff"
375-
]
376-
},
377-
{
378-
"cell_type": "markdown",
379-
"metadata": {
380-
"slideshow": {
381-
"slide_type": "subslide"
382-
}
383-
},
384-
"source": [
385-
"# Equality\n",
377+
"# Object Equality\n",
386378
"\n",
387-
"* The `__eq__()` magic method."
379+
"* The `__eq__(self, other)` magic method."
388380
]
389381
},
390382
{
@@ -576,7 +568,7 @@
576568
"source": [
577569
"### Now let's try it with Magic!\n",
578570
"\n",
579-
"* The `__eq__()` method is defined."
571+
"* The `__eq__()` magic method is defined."
580572
]
581573
},
582574
{
@@ -593,6 +585,17 @@
593585
"m_slc1 == m_slc2"
594586
]
595587
},
588+
{
589+
"cell_type": "markdown",
590+
"metadata": {
591+
"slideshow": {
592+
"slide_type": "fragment"
593+
}
594+
},
595+
"source": [
596+
"* That is exactly what we mean isn't it?!"
597+
]
598+
},
596599
{
597600
"cell_type": "markdown",
598601
"metadata": {
@@ -671,7 +674,7 @@
671674
"\n",
672675
"* Intuitively, the distance between two points is the difference.\n",
673676
"* This implies subtraction.\n",
674-
"* The `__sub__()` magic method."
677+
"* The `__sub__(self, other)` magic method."
675678
]
676679
},
677680
{
@@ -791,7 +794,11 @@
791794
}
792795
},
793796
"source": [
794-
"# Representation of objects"
797+
"# Representation of objects\n",
798+
"\n",
799+
"* The `__repr__(self)` magic method.\n",
800+
"* The `__str__(self)` magic method.\n",
801+
"* The `__format__(self, formatstr)` magic method."
795802
]
796803
},
797804
{
@@ -802,7 +809,7 @@
802809
}
803810
},
804811
"source": [
805-
"# `__repr__()`"
812+
"# `__repr__(self)`"
806813
]
807814
},
808815
{
@@ -855,7 +862,7 @@
855862
}
856863
},
857864
"source": [
858-
"# `__str__()`"
865+
"# `__str__(self)`"
859866
]
860867
},
861868
{
@@ -908,7 +915,7 @@
908915
}
909916
},
910917
"source": [
911-
"# `__format__()`"
918+
"# `__format__(self, formatstr)`"
912919
]
913920
},
914921
{
@@ -1151,7 +1158,7 @@
11511158
"source": [
11521159
"# Calling an object like a function\n",
11531160
"\n",
1154-
"* `__call__()`"
1161+
"* `__call__(self, [args...])`"
11551162
]
11561163
},
11571164
{
@@ -1187,7 +1194,10 @@
11871194
}
11881195
},
11891196
"source": [
1190-
"# `__del__()`"
1197+
"# Object Destruction\n",
1198+
"\n",
1199+
"* The `__del__(self)` magic method.\n",
1200+
"* Called when the object is garbage collected."
11911201
]
11921202
},
11931203
{
@@ -1252,7 +1262,7 @@
12521262
"name": "python",
12531263
"nbconvert_exporter": "python",
12541264
"pygments_lexer": "ipython3",
1255-
"version": "3.4.3"
1265+
"version": "3.5.1+"
12561266
}
12571267
},
12581268
"nbformat": 4,

0 commit comments

Comments
 (0)