Skip to content

Instantly share code, notes, and snippets.

@fohlin
Created October 11, 2010 20:59

Revisions

  1. fohlin revised this gist Mar 30, 2011. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion speaking_list.py
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,7 @@ def say(s):
    subprocess.call(['say', str(s)])

    class SpeakingList(list):
    """This custom lists speaks (if you're on OS X). Amazing!"""
    """This custom list speaks (if you're on OS X). Amazing!"""
    def __init__(self):
    super(SpeakingList, self).__init__()
    say("A new list is born!")
  2. fohlin revised this gist Oct 11, 2010. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion speaking_list.py
    Original file line number Diff line number Diff line change
    @@ -9,7 +9,7 @@ def say(s):
    class SpeakingList(list):
    """This custom lists speaks (if you're on OS X). Amazing!"""
    def __init__(self):
    super(SpeakingList, self).__init__(self)
    super(SpeakingList, self).__init__()
    say("A new list is born!")

    def append(self, value):
  3. fohlin created this gist Oct 11, 2010.
    22 changes: 22 additions & 0 deletions speaking_list.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    # 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 lists speaks (if you're on OS X). Amazing!"""
    def __init__(self):
    super(SpeakingList, self).__init__(self)
    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