renumbering chapters >= 19
This commit is contained in:
44
22-dyn-attr-prop/blackknight.py
Normal file
44
22-dyn-attr-prop/blackknight.py
Normal file
@@ -0,0 +1,44 @@
|
||||
"""
|
||||
This class is inspired by the Black Knight scene in the movie
|
||||
"Monty Python and the Holy Grail", where King Arthur fights the
|
||||
Black Knight, slicing off his arms and legs, but the knight
|
||||
refuses to concede defeat.
|
||||
|
||||
# tag::BLACK_KNIGHT_DEMO[]
|
||||
>>> knight = BlackKnight()
|
||||
>>> knight.member
|
||||
next member is:
|
||||
'an arm'
|
||||
>>> del knight.member
|
||||
BLACK KNIGHT (loses an arm) -- 'Tis but a scratch.
|
||||
>>> del knight.member
|
||||
BLACK KNIGHT (loses another arm) -- It's just a flesh wound.
|
||||
>>> del knight.member
|
||||
BLACK KNIGHT (loses a leg) -- I'm invincible!
|
||||
>>> del knight.member
|
||||
BLACK KNIGHT (loses another leg) -- All right, we'll call it a draw.
|
||||
|
||||
# end::BLACK_KNIGHT_DEMO[]
|
||||
"""
|
||||
|
||||
# tag::BLACK_KNIGHT[]
|
||||
class BlackKnight:
|
||||
|
||||
def __init__(self):
|
||||
self.phrases = [
|
||||
('an arm', "'Tis but a scratch."),
|
||||
('another arm', "It's just a flesh wound."),
|
||||
('a leg', "I'm invincible!"),
|
||||
('another leg', "All right, we'll call it a draw.")
|
||||
]
|
||||
|
||||
@property
|
||||
def member(self):
|
||||
print('next member is:')
|
||||
return self.phrases[0][0]
|
||||
|
||||
@member.deleter
|
||||
def member(self):
|
||||
member, text = self.phrases.pop(0)
|
||||
print(f'BLACK KNIGHT (loses {member}) -- {text}')
|
||||
# end::BLACK_KNIGHT[]
|
||||
Reference in New Issue
Block a user