callHooks generalizes some of the hook calling code in Optimize and Inversion

This commit is contained in:
Rowan Cockett
2013-11-21 16:56:01 -08:00
parent 0bd971c22f
commit dbaea1fda9
5 changed files with 28 additions and 34 deletions
+8
View File
@@ -61,6 +61,12 @@ def printStoppers(obj, stoppers, pad='', stop='STOP!', done='DONE!'):
print pad + stopper['str'] % (l<=r,l,r)
print pad + "%s%s%s" % ('-'*25,done,'-'*25)
def callHooks(obj, match, *args, **kwargs):
for method in [posible for posible in dir(obj) if ('_'+match) in posible]:
if getattr(obj,'debug',False): print (match+' is calling self.'+method)
getattr(obj,method)(*args, **kwargs)
import time
import numpy as np
@@ -154,6 +160,8 @@ def timeIt(f):
if type(counter) is Counter: counter.countToc(self.__class__.__name__+'.'+f.__name__)
return out
return wrapper
if __name__ == '__main__':
class MyClass(object):
def __init__(self, url):