ubelt.meta.dynamic_analysis module¶
-
ubelt.meta.dynamic_analysis.
get_stack_frame
(n=0, strict=True)[source]¶ Gets the current stack frame or any of its ancestors dynamically
Parameters: - n (int) – n=0 means the frame you called this function in. n=1 is the parent frame.
- strict (bool) – (default = True)
Returns: frame_cur
Return type: frame
- CommandLine:
- python -m dynamic_analysis get_stack_frame
Example
>>> from ubelt.meta.dynamic_analysis import * # NOQA >>> frame_cur = get_stack_frame(n=0) >>> print('frame_cur = %r' % (frame_cur,)) >>> assert frame_cur.f_globals['frame_cur'] is frame_cur
-
ubelt.meta.dynamic_analysis.
get_parent_frame
(n=0)[source]¶ Returns the frame of that called you. This is equivalent to get_stack_frame(n=1)
Parameters: n (int) – n=0 means the frame you called this function in. n=1 is the parent frame. Returns: parent_frame Return type: frame - CommandLine:
- python -m dynamic_analysis get_parent_frame
Example
>>> from ubelt.meta.dynamic_analysis import * # NOQA >>> root0 = get_stack_frame(n=0) >>> def foo(): >>> child = get_stack_frame(n=0) >>> root1 = get_parent_frame(n=0) >>> root2 = get_stack_frame(n=1) >>> return child, root1, root2 >>> # Note this wont work in IPython because several >>> # frames will be inserted between here and foo >>> child, root1, root2 = foo() >>> print('root0 = %r' % (root0,)) >>> print('root1 = %r' % (root1,)) >>> print('root2 = %r' % (root2,)) >>> print('child = %r' % (child,)) >>> assert root0 == root1 >>> assert root1 == root2 >>> assert child != root1