Bruno Desthuilliers wrote:
Would be better with :
return self.func(obj, *args, *kwds)
Thanks -- well spotted!
--
Greg
--
http://mail.python.org/mailman/listinfo/python-list
Gregory Ewing a écrit :
(snip)
import weakref
class weakmethod(object):
def __init__(self, bm):
self.ref = weakref.ref(bm.im_self)
self.func = bm.im_func
def __call__(self, *args, **kwds):
obj = self.ref()
if obj is None:
raise ValueError("Calling dead weak method")
I run into.
Regards,
Vincent
-Original Message-
From: python-list-bounces+v.vanbeveren=rijnhuizen...@python.org
[mailto:python-list-bounces+v.vanbeveren=rijnhuizen...@python.org] On Behalf Of
Christian Heimes
Sent: vrijdag 30 juli 2010 16:44
To: python-list@python.org
Subject: Re: The untimely
Hi Gregory,
> You can create your own wrapper that keeps a weak reference to
> the underlying object. Here's an example.
> [...]
Thanks for the code!
Regards,
Vincent
--
http://mail.python.org/mailman/listinfo/python-list
Vincent van Beveren wrote:
I was working with weak references in Python, and noticed that it
> was impossible to create a weak-reference of bound methods.
> is there anything I can do about it?
You can create your own wrapper that keeps a weak reference to
the underlying object. Here's an exa
Am 30.07.2010 16:06, schrieb Vincent van Beveren:
> I did not know the object did not keep track of its bound methods. What
> advantage is there in creating a new bound method object each time its
> referenced? It seems kind of expensive.
Instances of a class have no means of storing the bound m
Vincent van Beveren wrote:
> I did not know the object did not keep track of its bound methods. What
> advantage is there in creating a new bound method object each time its
> referenced? It seems kind of expensive.
While I didn't measure it I suppose that it saves a lot of memory.
Peter
--
htt
: vrijdag 30 juli 2010 15:06
To: python-list@python.org
Subject: Re: The untimely dimise of a weak-reference
Vincent van Beveren wrote:
> Hi everyone,
>
> I was working with weak references in Python, and noticed that it was
> impossible to create a weak-reference of bound methods. Here
Vincent van Beveren wrote:
> Hi everyone,
>
> I was working with weak references in Python, and noticed that it was
> impossible to create a weak-reference of bound methods. Here is a little
> python 3.0 program to prove my point:
>
> import weakref
>
> print("Creating object...")
> class A(obj
Hi everyone,
I was working with weak references in Python, and noticed that it was
impossible to create a weak-reference of bound methods. Here is a little python
3.0 program to prove my point:
import weakref
print("Creating object...")
class A(object):
def b(self):
print("I a
10 matches
Mail list logo