From e8c7d7a4de0c6cb8cf6760d4d07bd8001455b18d Mon Sep 17 00:00:00 2001 From: Zearin Date: Fri, 30 Dec 2011 12:30:54 -0500 Subject: Move documentation to top-level. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Following the examples I’ve seen in other Python projects. --- docs/pycon2010/pirate3.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 docs/pycon2010/pirate3.py (limited to 'docs/pycon2010/pirate3.py') 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() -- cgit v1.2.1