So I'm making a timer wrapper function, but I keep getting errors when trying to print the arguments.
My timer function looks like this:
def time_me(fn):
from time import time as t
def wrapper(*args, **kwargs):
start_time = t()
fn(*args, **kwargs)
end_time = t()
print("executing {} with arguments {}, took: {}".format(fn.__name__, *args, end_time - start_time))
return fn(*args, **kwargs)
return wrapper
Ideally it'd print the kwargs as well, but apparently that's a whole other issue, although I'd much appreciate if someone helped me with that. So what I have works fine when there's noly one argument:
@time_me
def dummy_fn(N):
from time import sleep as ts
ts(0.2)
return
dummy_fn(1000)
gives me: executing dummy_fn with arguments 1000, took: 0.2128157615661621
But if I redefine dummy_fn to take more arguments and pass them through it still only prints the first. When I tried to convert my *args to string I got errors saying that "str() argument 2 must be str, not int". I don't seem to be able to access my *args using for example the list() function either.
Does anyone know how to solve this?