Skip to content

Commit f0abdb8

Browse files
committed
Session 07 finished
1 parent de7ef46 commit f0abdb8

3 files changed

Lines changed: 99 additions & 38 deletions

File tree

lightning_schedule.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ week 6: Alexander R Galvin
1919
week 6: Gideon I Sylvan
2020
week 6: Hui Zhang
2121
week 7: Andrew P Klock
22-
week 7: Danielle G Marcos
22+
week 7: Danielle G Marcos ** still needs to do it **
2323
week 7: Ousmane Conde
2424
week 7: Salim Hassan Hamed
2525
week 8: Alireza Hashemloo
2626
week 8: Arielle R Simmons
2727
week 8: Eric W Westman
2828
week 8: Ryan J Albright
29-
week 9: Alexandra N Kazakova
29+
week 9: Alexandra N Kazakova ** needs to be re-sheduled **
3030
week 9: Erik Ivan Lottsfeldt
3131
week 9: Louis John Ascoli
3232
week 9: Ralph P Brand

slides_sources/source/homework/circle_class.rst

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ Add an ``area`` property so the user can get the area of the circle:
106106
>> print c.area
107107
12.566370
108108
109-
NOTE: ``pi`` can be found in the math module
109+
(``pi`` can be found in the math module)
110110

111111
The user should not be able to set the area:
112112

@@ -135,7 +135,7 @@ Step 6:
135135

136136
Add __str__ and __repr__ methods to your Circle class.
137137

138-
Now you cant print it:
138+
Now you can print it:
139139

140140
.. code-block:: ipython
141141
@@ -157,7 +157,7 @@ Step 7:
157157

158158
Add some of the numeric protocol to your Circle:
159159

160-
you should be able to add two circles:
160+
You should be able to add two circles:
161161

162162
.. code-block:: ipython
163163
@@ -175,9 +175,16 @@ and multiply one times a number:
175175
In [16]: c2 * 3
176176
Out[16]: Circle(12)
177177
178-
and compare them:
178+
(what happens with ``3 * c2`` ? -- can you fix that?)
179+
180+
.. nextslide::
181+
182+
Step 8:
183+
--------
184+
add the ability to compare two circles:
179185

180186
.. code-block:: ipython
187+
181188
In [10]: c1 > c2
182189
Out[10]: False
183190
@@ -192,3 +199,44 @@ and compare them:
192199
In [14]: c2 == c3
193200
Out[14]: True
194201
202+
.. nextslide::
203+
204+
Once the comparing is done, you should be able to sort a list of circles:
205+
206+
.. code-block:: ipython
207+
208+
In [18]: print circles
209+
[Circle(6), Circle(7), Circle(8), Circle(4), Circle(0), Circle(2), Circle(3), Circle(5), Circle(9), Circle(1)]
210+
211+
In [19]: circl
212+
circle circle.py circle.pyc circles
213+
214+
In [19]: circles.sort()
215+
216+
In [20]: print circles
217+
[Circle(0), Circle(1), Circle(2), Circle(3), Circle(4), Circle(5), Circle(6), Circle(7), Circle(8), Circle(9)]
218+
219+
**NOTE:** make sure to write unit tests for all of this! Ideally before writing the code.
220+
221+
Step 8: Optional Features:
222+
--------------------------
223+
224+
* See if you can make "reflected" numerics do the right thing:
225+
226+
.. code-block:: python
227+
228+
a_circle * 3 == 3 * a_circle
229+
230+
* What else makes sense: division? others?
231+
232+
* Add the "augmented assignment" operators, where they make sense:
233+
234+
.. code-block:: python
235+
236+
a_circle += another_circle
237+
238+
a_circle *= 2
239+
240+
* look through all the "magic methods" and see what makes sense for circles
241+
242+

slides_sources/source/session07.rst

Lines changed: 45 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,21 @@
22
.. Foundations 2: Python slides file, created by
33
hieroglyph-quickstart on Wed Apr 2 18:42:06 2014.
44
5-
*******************************************************
6-
Session Seven: More OO -- Properties, special methods.
7-
*******************************************************
5+
***********************
6+
Session Seven: More OO
7+
***********************
88

9-
.. rst-class:: large centered
9+
.. rst-class:: medium centered
1010

11-
| Multiple Inheritance,
12-
| Properties,
13-
| classmethods and staticmethods,
14-
| Special (Magic) Methods
11+
.. container::
12+
13+
Multiple Inheritance
14+
15+
Properties
16+
17+
Class methods and static methods
18+
19+
Special (Magic) Methods
1520

1621
================
1722
Review/Questions
@@ -67,25 +72,13 @@ Lightning Talks Today:
6772

6873
.. rst-class:: medium
6974

70-
Andrew P Klock
75+
Andrew P Klock
7176

72-
Vinay Gupta
73-
74-
Ousmane Conde
75-
76-
Salim Hassan Hamed
77-
78-
79-
Lightning Talks
80-
----------------
77+
Vinay Gupta
8178

82-
.. rst-class:: medium
79+
Ousmane Conde
8380

84-
|
85-
| Ousmane Conde
86-
|
87-
| Salim Hassan Hamed
88-
|
81+
Salim Hassan Hamed
8982

9083

9184
===================
@@ -100,7 +93,7 @@ More on Subclassing
10093

10194
http://pyvideo.org/video/879/the-art-of-subclassing
10295

103-
If you haven't watched, It's well worth your time
96+
If you haven't watched it, It's well worth your time
10497

10598

10699
What's a Subclass For?
@@ -161,7 +154,7 @@ So why would you want to do this? One reason: *mixins*
161154

162155
Provides an subset of expected functionality in a re-usable package.
163156

164-
Why would you want to do this?
157+
Huh? this is why --
165158

166159
Hierarchies are not always simple:
167160

@@ -229,8 +222,9 @@ Caution: There are some subtle differences with multiple inheritance.
229222

230223
You can use explicit calling to ensure that the 'right' method is called.
231224

225+
.. rst-class:: medium
232226

233-
.. nextslide:: Background
227+
**Background**
234228

235229
Two seminal articles about ``super()``:
236230

@@ -422,7 +416,7 @@ Lightning Talks
422416
Static and Class Methods
423417
========================
424418

425-
.. rst-class:: left build
419+
.. rst-class:: left build
426420
.. container::
427421

428422
You've seen how methods of a class are *bound* to an instance when it is
@@ -461,7 +455,6 @@ A *static method* is a method that doesn't get self:
461455
[demo: :download:`static_method.py <../../Examples/Session07/static_method.py>`]
462456

463457

464-
465458
.. nextslide:: Why?
466459

467460
.. rst-class:: build
@@ -725,8 +718,26 @@ There's more to read about the details of implementing these methods:
725718
* https://docs.python.org/2/reference/datamodel.html#special-method-names
726719
* http://www.rafekettler.com/magicmethods.html
727720

728-
Be a bit cautious about the code examples in that last one. It uses quite a bit
729-
of old-style class definitions, which should not be emulated.
721+
722+
Lightning Talks
723+
----------------
724+
725+
.. rst-class:: medium
726+
727+
|
728+
| Ousmane Conde
729+
|
730+
| Salim Hassan Hamed
731+
|
732+
733+
LAB
734+
----
735+
736+
Let's complete our nifty Circle class:
737+
738+
Steps 5-8 of:
739+
740+
:ref:`homework_circle_class`
730741

731742

732743
========
@@ -735,4 +746,6 @@ Homework
735746

736747
Complete the Circle class
737748

738-
Decide what you are going to do for your proejct,
749+
Decide what you are going to do for your proejct, and send me a simple proposal.
750+
751+

0 commit comments

Comments
 (0)