summaryrefslogtreecommitdiff
path: root/docs/pycon2010/pirate5.py
diff options
context:
space:
mode:
authorZearin <zearin@gonk.net>2011-10-05 17:05:31 -0400
committerZearin <zearin@gonk.net>2011-10-05 17:05:31 -0400
commitaa19e3b9c9f03f7320c2d5470fa977ed0bbdeeab (patch)
tree97d86fe3a03114be08aac12a7097aa80ac03bc2a /docs/pycon2010/pirate5.py
downloadcmd2-aa19e3b9c9f03f7320c2d5470fa977ed0bbdeeab.tar.gz
Initial import.
Copy of the Python module cmd2 by Catherine Devlin. Note that this is NOT the official copy (it’s at http://www.assembla.com/spaces/python-cmd2/wiki ). I’d rather just work using git + GitHub instead of hg + Assembla. ☺ OTOH, I fully intend to submit changes back to the official repo on Assembla—so don’t be shy, fork away. I’m happy for any help!
Diffstat (limited to 'docs/pycon2010/pirate5.py')
-rw-r--r--docs/pycon2010/pirate5.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/docs/pycon2010/pirate5.py b/docs/pycon2010/pirate5.py
new file mode 100644
index 0000000..7add463
--- /dev/null
+++ b/docs/pycon2010/pirate5.py
@@ -0,0 +1,35 @@
+from cmd import Cmd
+# quitting
+
+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.
+
+ drink [n] - drink [n] barrel[s] o' rum.'''
+ try:
+ self.gold -= int(arg)
+ except:
+ if arg:
+ print('''What's "{0}"? I'll take rrrum.'''.format(arg))
+ 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))
+ if self.gold < 0:
+ print("Off to debtorrr's prison.")
+ stop = True
+ return stop
+ def do_quit(self, arg):
+ print("Quiterrr!")
+ return True
+
+pirate = Pirate()
+pirate.cmdloop()