Is there a standard method to repr
the call that resulted in a given stack frame in Python? Failing that, is there a nice way to do it manually?
As an example:
def some_call(*args, **kwargs):
print('{}({})'.format(
'some_call',
', '.join(itertools.chain(
map(repr, args),
('{}={!r}'.format(k, kwargs[k]) for k in kwargs)))))
>>> some_call(1, 2, a=3)
some_call(1, 2, a=3)
I'm attempting to log certain calls, and am writing a decorator that logs calls to the wrapped function with full details. Am I going about this wrong?
I'm not quite sure what you're asking, but you can use the inspect module to get all the current stack info.
You can regenerate the calling of your current frame using
inspect.getargvalues
, and format it to your liking