weak reference to bound method
Ole Streicher
ole-usenet-spam at gmx.net
Fri Oct 2 06:10:19 EDT 2009
Hi Miles,
Miles Kaufmann <milesck at umich.edu> 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 = weakref.ref(bound_method.im_self)
> self.im_class = bound_method.im_class
In this case, I can use it only for bound methods, so I would need to
handle the case of unbound methods separately.
Is there a way to find out whether a function is bound? Or do I have to
use hasattr(im_func) and hasattr(im_self) and hasattr(im_class)?
Best regards
Ole
More information about the Python-list
mailing list