Jan-09-2017, 03:02 PM
I have put your code in a separate Python file (which I import as a module in my "executable" .py file), with slight modifications:
I added:
"def __init__(self, function, max_iters=1, seconds=0)"
and replaced
"print('T minus {}'.format(self.max_iters))" with a call to function I would like to execute with the timer:
function()
Of course "function" is defined in the separate file with main code to be executed, so there is an unresolved reference. What would be a good way around this? Obviously I could put the Timer definitions you wrote in the same file as the rest of the code. But I would like to keep it clear and modular if possible.
I added:
"def __init__(self, function, max_iters=1, seconds=0)"
and replaced
"print('T minus {}'.format(self.max_iters))" with a call to function I would like to execute with the timer:
function()
Of course "function" is defined in the separate file with main code to be executed, so there is an unresolved reference. What would be a good way around this? Obviously I could put the Timer definitions you wrote in the same file as the rest of the code. But I would like to keep it clear and modular if possible.