russell_h
russell_h

Reputation: 966

See What Line a Function Was Called From in Python Decorator

Given something like this:

@my_decorator
my_function(some, args)

Is it possible for my_decorator to discover the file and line number my_function was called from?

Thanks

Upvotes: 3

Views: 258

Answers (1)

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798606

traceback.extract_stack() will allow you to examine the current stack frame.

Upvotes: 4

Related Questions