Convenience functions for the python execution stack.
Project description
Release 20190812: stack_dump(): trim the last 2 frames from the listing by default (they are part of stack_dump's implementation).
I find the supplied python traceback facilities quite awkward. These functions provide convenient facilities.
Function caller(frame_index=-3)
Return the Frame
of the caller's caller.
Useful frame_index
values:
-1
: caller, this function-2
: invoker, who wants to know the caller-3
: the calling function of the invoker
The default from_index
value is -3
.
Class Frame
MRO: Frame
, builtins.tuple
A namedtuple
for stack frame contents.
Function frames()
Return the current stack as a list of Frame
objects.
Function stack_dump(fp=None, indent=0, Fs=None, skip=None)
Recite current or supplied stack to fp
, default sys.stderr
.
Parameters:
fp
: the output file object, defaultsys.stderr
indent
: how many spaces to indent the stack lines, default0
Fs
: the stackFrame
s to write, default obtained from the current stackskip
: the number ofFrame
s to trim from the end ofFs
; ifFs
isNone
this defaults to2
to trim theFrame
s for thestack_dump
function and its call toframes()
, otherwise the default is0
to use the suppliedFrame
s as is
Release Log
Release 20190812: stack_dump(): trim the last 2 frames from the listing by default (they are part of stack_dump's implementation).
Release 20190101: _Frame: rename .functionname to .funcname; caller: turn raw frames into Frames. caller(): accept optional frame_index, default -3.
Release 20160827: Add stack_dump().
Release 20150115: PyPI metadata fixups.
Release 20150111: Tag for initial PyPI release of cs.py.stack.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.