The metaclass approach seems to be the one I was looking for. Thanks!
Bert
--
http://mail.python.org/mailman/listinfo/python-list
Ben Cartwright wrote:
> [EMAIL PROTECTED] wrote:
> > Hey, I have the following code that has to send every command it
> > receives to a list of backends.
>
> > I would like to write each method like:
> >
> > flush = multimethod()
>
> Here's one way, using a metaclass:
Or if you don't mind a
[EMAIL PROTECTED] wrote:
> Hey, I have the following code that has to send every command it
> receives to a list of backends.
> I would like to write each method like:
>
> flush = multimethod()
Here's one way, using a metaclass:
class multimethod(object):
def transform(self, attr):
Scott David Daniels wrote:
>
> class Forwards(object):
>
> to_forward = set(['flush', 'read', 'write', 'close'])
>
> def __init__(self, backends):
> self.backends = backends
>
> def forwarder(self, methodname):
> def method(*args, **kwargs):
> for b in se
[EMAIL PROTECTED] wrote:
> Hey, I want to send commands to a list of backends:
How about something like:
class Forwards(object):
to_forward = set(['flush', 'read', 'write', 'close'])
def __init__(self, backends):
self.backends = backends
def forwarder(self, methodname)
[EMAIL PROTECTED] wrote:
> Hey, I have the following code that has to send every command it
> receives to a list of backends. Instead of:
>
> class MultiBackend(object):
> """Renders to multiple backends"""
>
> def __init__(self, backends):
> self.backends = backends
>
> def
Hey, I have the following code that has to send every command it
receives to a list of backends. Instead of:
class MultiBackend(object):
"""Renders to multiple backends"""
def __init__(self, backends):
self.backends = backends
def flush(self):
for b in self.backends: