Observer implementations

I V ivlenin at
Mon Jun 15 23:11:18 EDT 2009

On Mon, 15 Jun 2009 15:29:34 +0200, Tobias Weber wrote:
> Despite the confusion all those are useable, but I ran into the problem
> that I can't register a @classmethod because weakref doesn't like them.

What do you mean by weakref not liking class methods? This seems to work 
OK on python 2.6

class C(object):
	def cm(cls):
		return "Class method of " + str(cls)

cm =
print cm()
# Outputs:
# Class method of <class '__main__.C'>

w = weakref.ref(cm)
print w	
# Outputs: 
# <weakref at 0x1a362b8; to 'instancemethod' at 0x7ff1cc9ebb40 (cm)>

print w()
# Outputs: 
# <bound method of <class '__main__.C'>>

print w()()
# Outputs:
# Class method of <class '__main__.C'>

del cm
print w
# Outputs:
# <weakref at 0x1a362b8; dead>

More information about the Python-list mailing list