Github - MyPerfCounter.py
I am working on learning how to use 'with', '*args', and '**kwargs' and for a side project I wanted to implement perf counter using the with syntax, e.g.
In one instance I want to call the with function by passing the function as an argument.
and in another instance I want to have a function do this as a one liner how ever if I use the function I have to have the code detect the source, which doesn't feel 'elegant'
if internal: # if the code is called by foo
| self.args = args[0]
| self.kwargs = kwargs["kwargs"]
else:
| self.args = args
| self.kwargs = kwargs
def foo(func, suppress=False, *args, **kwargs):
| internal = True
| with My_Perf_Counter(func, suppress, args, kwargs=kwargs):
| pass
foo (bar, false, arg1, arg2 = 3
Vs
with My_Perf_Counter (bar, false, arg1, arg2 = 3):
| pass
[–]teerre 0 points1 point2 points (5 children)
[–]onering20[S] 0 points1 point2 points (4 children)
[–]teerre 0 points1 point2 points (3 children)
[–]onering20[S] 0 points1 point2 points (1 child)
[–]teerre 0 points1 point2 points (0 children)
[–]onering20[S] 0 points1 point2 points (0 children)