Skip to content

Instantly share code, notes, and snippets.

@luhn
Created March 31, 2019 23:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luhn/d1dac5eff4d6fd0018ae12eac48e94e0 to your computer and use it in GitHub Desktop.
Save luhn/d1dac5eff4d6fd0018ae12eac48e94e0 to your computer and use it in GitHub Desktop.
import sys
import inspect
def wrap(func):
attach()
return func
def attach():
frame = sys._getframe(2)
info = inspect.getframeinfo(frame)
# Python 3.7: "@wrap"
# Python 3.8: "def a():"
print(info.code_context[0])
@wrap
def a():
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment