Print the value of an expression from the caller's frame. Takes an expression, evaluates it in the caller's frame and prints both the given expression and the resulting value (as well as a debug mark indicating the name of the calling function. The input must be of a form suitable
(expr,pre_msg='')
| 68 | |
| 69 | |
| 70 | def debugx(expr,pre_msg=''): |
| 71 | """Print the value of an expression from the caller's frame. |
| 72 | |
| 73 | Takes an expression, evaluates it in the caller's frame and prints both |
| 74 | the given expression and the resulting value (as well as a debug mark |
| 75 | indicating the name of the calling function. The input must be of a form |
| 76 | suitable for eval(). |
| 77 | |
| 78 | An optional message can be passed, which will be prepended to the printed |
| 79 | expr->value pair.""" |
| 80 | |
| 81 | cf = sys._getframe(1) |
| 82 | print('[DBG:%s] %s%s -> %r' % (cf.f_code.co_name,pre_msg,expr, |
| 83 | eval(expr,cf.f_globals,cf.f_locals))) |
| 84 | |
| 85 | |
| 86 | # deactivate it by uncommenting the following line, which makes it a no-op |
nothing calls this directly
no outgoing calls
no test coverage detected