Created
October 11, 2010 20:59
-
-
Save fohlin/621216 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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