Created
August 25, 2015 00:37
-
-
Save GrahamDumpleton/01d962cb085c28184819 to your computer and use it in GitHub Desktop.
Qualified name of function being executed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Can't get class via stack frame as only have access to code object and not what type it may have been bound to if a function. | |
>>> def func(): | |
... print sys._getframe().f_code.co_name | |
... | |
>>> func() | |
func | |
>>> class A(object): | |
... def method(self): | |
... print sys._getframe().f_code.co_name | |
... | |
>>> A().method() | |
method | |
# Even if use profile hook can't do it, as all one can get is stack frame again. | |
>>> def hook(*args): | |
... print args | |
... | |
>>> sys.setprofile(hook) | |
(<frame object at 0x101a56dd0>, 'return', None) | |
>>> A().method() | |
(<frame object at 0x101ba8050>, 'call', None) | |
(<frame object at 0x101ba8050>, 'c_call', <built-in function utf_8_decode>) | |
(<frame object at 0x101ba8050>, 'c_return', <built-in function utf_8_decode>) | |
(<frame object at 0x101ba8050>, 'return', (u'A().method()\n', 13)) | |
(<frame object at 0x101b9a1f8>, 'call', None) | |
(<frame object at 0x101a56c20>, 'call', None) | |
(<frame object at 0x101a56c20>, 'c_call', <built-in function _getframe>) | |
(<frame object at 0x101a56c20>, 'c_return', <built-in function _getframe>) | |
method | |
(<frame object at 0x101a56c20>, 'return', None) | |
(<frame object at 0x101b9a1f8>, 'return', None) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment