Skip to content

Instantly share code, notes, and snippets.

@luhn
Created March 31, 2019 23:27
Show Gist options
  • Save luhn/d1dac5eff4d6fd0018ae12eac48e94e0 to your computer and use it in GitHub Desktop.
Save luhn/d1dac5eff4d6fd0018ae12eac48e94e0 to your computer and use it in GitHub Desktop.

Revisions

  1. luhn created this gist Mar 31, 2019.
    20 changes: 20 additions & 0 deletions frameinfo.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    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