weakrefs and bound methods

Mathias Panzenboeck e0427417 at student.tuwien.ac.at
Sun Oct 7 16:59:40 CEST 2007


When I change the class Wrapper to following, the class Foo works:

class Wrapper(object):
	def __init__(self,x):
		self.func_name = x.func_name
		self.x         = weakref.ref(x.im_self)

	def __call__(self,*args,**kwargs):
		x = self.x()
		if x is None:
			print "lost reference"
		else:
			return getattr(x,self.func_name)(*args,**kwargs)


But that's ugly. Any better idea?



More information about the Python-list mailing list