Re: Automatic methods in new-style classes

2006-09-30 Thread bertgoos
The metaclass approach seems to be the one I was looking for. Thanks! Bert -- http://mail.python.org/mailman/listinfo/python-list

Re: Automatic methods in new-style classes

2006-09-29 Thread George Sakkis
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

Re: Automatic methods in new-style classes

2006-09-29 Thread Ben Cartwright
[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):

Re: Automatic methods in new-style classes

2006-09-29 Thread Scott David Daniels
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

Re: Automatic methods in new-style classes

2006-09-29 Thread Scott David Daniels
[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)

Re: Automatic methods in new-style classes

2006-09-29 Thread Peter Otten
[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

Automatic methods in new-style classes

2006-09-29 Thread bertgoos
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: