blob: 7977a8dc29141672784bda5a3d4a3a471c801395 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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()
|