Re: Injecting methods into instance / class

2018-12-03 Thread Peter Otten
duncan smith wrote: > On 02/12/2018 18:36, Peter Otten wrote: >> class CommonMethods: >> __add__ = add > Ah, I could just bind them within the class, > > mean = mean > max = max etc. > > but I'd somehow convinced myself that didn't work. As the names are the > same I'd probably sti

Re: Injecting methods into instance / class

2018-12-02 Thread duncan smith
On 02/12/2018 18:36, Peter Otten wrote: > duncan smith wrote: > >> Hello, >> I have a lot of functions that take an instance of a particular >> class as the first argument. I want to create corresponding methods in >> the class. I have tried the following, which (when called from __init__) >

Re: Injecting methods into instance / class

2018-12-02 Thread Thomas Jollans
On 02/12/2018 18:56, duncan smith wrote: > Hello, > I have a lot of functions that take an instance of a particular > class as the first argument. I want to create corresponding methods in > the class. I have tried the following, which (when called from __init__) > creates the relevant method

Re: Injecting methods into instance / class

2018-12-02 Thread duncan smith
On 02/12/2018 18:26, Stefan Ram wrote: > duncan smith writes: >> I have tried to find examples of injecting methods into classes without > > Wouldn't the normal approach be to just define a > class with your functions as instance methods? > > main.py > > class C(): > def __init__( sel

Re: Injecting methods into instance / class

2018-12-02 Thread Peter Otten
duncan smith wrote: > Hello, > I have a lot of functions that take an instance of a particular > class as the first argument. I want to create corresponding methods in > the class. I have tried the following, which (when called from __init__) > creates the relevant methods in an instance (Py

Re: Injecting methods into instance / class

2018-12-02 Thread Morten W. Petersen
Hi Duncan. On Sun, Dec 2, 2018 at 7:02 PM duncan smith wrote: > Hello, > I have a lot of functions that take an instance of a particular > class as the first argument. I want to create corresponding methods in > the class. I have tried the following, which (when called from __init__) > cre

Injecting methods into instance / class

2018-12-02 Thread duncan smith
Hello, I have a lot of functions that take an instance of a particular class as the first argument. I want to create corresponding methods in the class. I have tried the following, which (when called from __init__) creates the relevant methods in an instance (Python 3.6). def init_methods(s