Skip to content

Instantly share code, notes, and snippets.

@fohlin
Created October 11, 2010 20:59
Show Gist options
  • Save fohlin/621216 to your computer and use it in GitHub Desktop.
Save fohlin/621216 to your computer and use it in GitHub Desktop.
# Using the OS X "say" command to demo inheritance
# Thanks to Simon Willison for inspiration: http://gist.github.com/267147
import subprocess
def say(s):
subprocess.call(['say', str(s)])
class SpeakingList(list):
"""This custom list speaks (if you're on OS X). Amazing!"""
def __init__(self):
super(SpeakingList, self).__init__()
say("A new list is born!")
def append(self, value):
super(SpeakingList, self).append(value)
say("Added: %s" % value)
def __len__(self):
l = super(SpeakingList, self).__len__()
say("The list length is %s" % l)
return l
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment