On Wed, Sep 14, 2022 at 6:05 AM אורי wrote:
> Hi,
>
> Python 3.9.14 has been released on Sept. 6, 2022. As I can see written on
> https://www.python.org/downloads/release/python-3914/:
>
> According to the release calendar specified in PEP 596, Python 3.9 is now
> in the "security fixes only
Here is an example of probably the easiest way to add an instance method:
class Demo:
def sqr(self, x):
return x*x
# Function to turn into a instance method
def cube(self, x):
return x*x*x
d = Demo()
print(d.sqr(2))
d.cube = cube.__get__(d)
print(d.cube(3))
As for when someone
On Fri, Sep 16, 2022 at 2:06 PM Ralf M. wrote:
> I would like to replace a method of an instance, but don't know how to
> do it properly.
>
You appear to have a good answer, but... are you sure this is a good idea?
It'll probably be confusing to future maintainers of this code, and I doubt
sta
On 9/16/22, Ralf M. wrote:
> I would like to replace a method of an instance, but don't know how to
> do it properly.
A function is a descriptor that binds to any object as a method. For example:
>>> f = lambda self, x: self + x
>>> o = 42
>>> m = f.__get__(o)
>>> type(m)
On Sat, 17 Sept 2022 at 07:07, Ralf M. wrote:
>
> I would like to replace a method of an instance, but don't know how to
> do it properly.
>
> My first naive idea was
>
> inst = SomeClass()
> def new_method(self, param):
> # do something
> return whatever
> inst.method = new_method
>
> h
I would like to replace a method of an instance, but don't know how to
do it properly.
My first naive idea was
inst = SomeClass()
def new_method(self, param):
# do something
return whatever
inst.method = new_method
however that doesn't work: self isn't passed as first parameter to
the