Python Closure + Oop
I'm trying to do something a bit strange (at least to me) with python closure. Say I have 2 classes like this: #!/usr/bin/python import types def method_a(self): print 'ma %d'
Solution 1:
Give the inner self another name:
deffoo(self, a):
defclosuer(b):
print"closure %d, %d" % (self.val, a)
return closuer
Also, rather then using types.MethodType, you might want to use functools.partial
Post a Comment for "Python Closure + Oop"