Function docstring as a local variable
chardster at gmail.com
Sun Jul 10 17:16:05 EDT 2011
> >>> def findself():
> """Find myself. Ooh look, there I am!"""
> import sys
> # Now I'm not sure what to do with traceback.
> # traceback.tb_frame.f_code.co_name is the function name ("findself").
> # Is there a way to get the function object?
I'm pretty sure there isn't. I've tried a number of times before to
find it but failed. Fundamentally frame objects don't need to know
about functions. Functions are just one way of wrapping code objects
but sometimes code objects come in modules.
You can use sys._getframe() to get the current frame instead of the
More information about the Python-list