Hi I was going through the Runner
class implementation in lesson 9, a little bit confused why does it takes both callbacks (i.e. the parameter cbs
) and callback functions (the parameter cb_funcs
) to its __init__
method;
class Runner():
def __init__(self, cbs=None, cb_funcs=None):
cbs = listify(cbs)
for cbf in listify(cb_funcs):
cb = cbf()
setattr(self, cb.name, cb)
cbs.append(cb)
self.stop,self.cbs = False,[TrainEvalCallback()]+cbs
Jeremy explained in the lecture that he thinks it is a little bit awkward that you have to store the callbacks in a variable in order to access it later; but with callback functions, you do not have to store it away and can access the callback objects from the Runner
object directly.
However from my understanding, this is the case only because it registered all the callbacks created by callback functions to the Runner’s name space during initialization,
for cbf in listify(cb_funcs): cb = cbf() setattr(self, cb.name, cb)
it did not try to register the callbacks to the Runner’s name space during its __init__
, we can easily add something like
for cb in cbs: setattr(self,cb.name,cb)
so that you will be able to access the callbacks same way as you access callback functions from the runner instance
so I’m really confused can anyone tells me under what scenarios we need callback functions instead callbacks?