diff options
Diffstat (limited to 'docs/pycon2010/pirate3.py')
-rw-r--r-- | docs/pycon2010/pirate3.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/docs/pycon2010/pirate3.py b/docs/pycon2010/pirate3.py new file mode 100644 index 0000000..7977a8d --- /dev/null +++ b/docs/pycon2010/pirate3.py @@ -0,0 +1,21 @@ +from cmd import Cmd +# using hook + +class Pirate(Cmd): + gold = 3 + def do_loot(self, arg): + 'Seize booty from a passing ship.' + self.gold += 1 + def do_drink(self, arg): + 'Drown your sorrrows in rrrum.' + self.gold -= 1 + def precmd(self, line): + self.initial_gold = self.gold + return line + def postcmd(self, stop, line): + if self.gold != self.initial_gold: + print('Now we gots {0} doubloons' + .format(self.gold)) + +pirate = Pirate() +pirate.cmdloop() |