On Tue, Jul 28, 2009 at 1:22 PM, Mac Ryan<quasipe...@gmail.com> wrote:

> def invokeAll(method, data):
>    """This function is a dispatcher: it invokes all the content types
>    of the application calling 'contenttype.method(data)'"""
>    return [getattr(content, method)(data) for content in contents]

In Python 2.6 you can use operator.methodcaller() to do this:
def invokeAll(method, data):
  caller = operator.methodcaller(method, data)
  return map(caller, contents)

> mycontent = ContentA()
> contents.append(mycontent)

This is not so bad. You could also make a class member of the base
class that keeps track of instances:
class ContentA(object):
  contents = []
  def __init__(self):
    contents.append(self)

Kent
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to