On Oct 2, 4:54 am, Ole Streicher wrote:
> Hi group,
>
> I am trying to use a weak reference to a bound method:
>
> class MyClass(object):
> def myfunc(self):
> pass
>
> o = MyClass()
> print o.myfunc
>
> >
>
> import weakref
> r = weakref.ref(o.myfunc)
> print r()
>
> Non
Hi Peter,
Peter Otten <__pete...@web.de> writes:
I am a bit surprised that already such a simple problem is virtually
unsolvable in python.
> Btw, have you implemented such a design in another language?
No.
> I think I'd go for a simpler approach, manage the lifetime of MyClass
> i
Ole Streicher wrote:
> Hi Peter,
>
> Peter Otten <__pete...@web.de> writes:
>> Ole Streicher wrote:
>>> Peter Otten <__pete...@web.de> writes:
> What I want is to have a universal class that "always" works: with
> unbound functions, with bound function, with lambda expressions, with
>
Hi Peter,
Peter Otten <__pete...@web.de> writes:
> class Method(object):
> def __init__(self, obj, func=None):
> if func is None:
> func = obj.im_func
> obj = obj.im_self
This requires that func is a bound method. What I want is to have a
universal class that "
Hi Peter,
Peter Otten <__pete...@web.de> writes:
> Ole Streicher wrote:
>> Peter Otten <__pete...@web.de> writes:
What I want is to have a universal class that "always" works: with
unbound functions, with bound function, with lambda expressions, with
locally defined functions,
>>> T
Ole Streicher wrote:
> Hello Peter,
>
> Peter Otten <__pete...@web.de> writes:
>>> What I want is to have a universal class that "always" works: with
>>> unbound functions, with bound function, with lambda expressions, with
>>> locally defined functions,
>
>> That's left as an exercise to the re
Hello Peter,
Peter Otten <__pete...@web.de> writes:
>> What I want is to have a universal class that "always" works: with
>> unbound functions, with bound function, with lambda expressions, with
>> locally defined functions,
> That's left as an exercise to the reader ;)
Do you have the feeling t
Ole Streicher wrote:
> Peter Otten <__pete...@web.de> writes:
>> class Method(object):
>> def __init__(self, obj, func=None):
>> if func is None:
>> func = obj.im_func
>> obj = obj.im_self
>
> This requires that func is a bound method. What I want is to have a
> I am trying to use a weak reference to a bound method:
>
> class MyClass(object):
> def myfunc(self):
> pass
>
> o = MyClass()
> print o.myfunc
> >
>
> import weakref
> r = weakref.ref(o.myfunc)
> print r()
> None
>
> This is what I do not understand. The object "o" is s
Hi Miles,
Miles Kaufmann writes:
> You could also create a wrapper object that holds a weak reference to the
> instance and creates a bound method on demand:
> class WeakMethod(object):
> def __init__(self, bound_method):
> self.im_func = bound_method.im_func
> self.im_self =
Ole Streicher wrote:
> Hi Thomas,
>
> Thomas Lehmann writes:
>>> r = weakref.ref(o.myfunc)
>>> print r()
>>> None
>> k = o.myfunc
>> r = weakref.ref(k)
>> print r()
>>>
>
>> Don't ask me why! I have just been interested for what you are trying...
>
> This is clear: in your case, o
Hello Peter,
Peter Otten <__pete...@web.de> writes:
> Is there an actual use case?
I discussed this in the german newsgroup. Here is the use in my class:
-8<---
import threading
import weakref
class DoAsync(threading.Thread):
def __init__(self,
On Oct 2, 2009, at 1:54 AM, Ole Streicher wrote:
I am trying to use a weak reference to a bound method:
class MyClass(object):
def myfunc(self):
pass
o = MyClass()
print o.myfunc
0xc675d0>>
import weakref
r = weakref.ref(o.myfunc)
print r()
None
This is what I do not understand
Hi Thomas,
Thomas Lehmann writes:
>> r = weakref.ref(o.myfunc)
>> print r()
>> None
> k = o.myfunc
> r = weakref.ref(k)
> print r()
>>
> Don't ask me why! I have just been interested for what you are trying...
This is clear: in your case, o.myfunc is explicitely referenced by k,
th
Ole Streicher wrote:
> I am trying to use a weak reference to a bound method:
>
> class MyClass(object):
> def myfunc(self):
> pass
>
> o = MyClass()
> print o.myfunc
> 0xc675d0>>
>
> import weakref
> r = weakref.ref(o.myfunc)
> print r()
> None
>
> This is what
15 matches
Mail list logo