Skip to main content

Shows a simplified view of the call stack.

Project description

ShowCallStack

Shows a simplified view of the call stack.

This module is similar to Python's built-in traceback and inspect modules, but is easier to use and displays more simple output. This module is useful for demonstrating what the call stack looks like during recursive function calls. Simply add a from showcallstack import showCallStack line and then call showCallStack() from wherever you wish to see the state of the call stack and the local variables in each call frame.

Example Usage

This program...

from showcallstack import showcallstack

def a():
    varA = 42
    b()

def b():
    varB = 86
    c()

def c():
    varC = 99
    showcallstack()

a()

...outputs this:

The call stack is 3 call(s) deep:
Function/method: a(), Local variables: {'varA': 42}
Function/method: b(), Local variables: {'varB': 86}
Function/method: c(), Local variables: {'varC': 99}

This recursive factorial program...

from showcallstack import showcallstack

def factorial(num):
    showcallstack()
    if num == 1:
        return 1
    else:
        return num * factorial(num - 1)

factorial(4)

...outputs this:

The call stack is 1 call(s) deep:
Function/method: factorial(), Local variables: {'num': 4}

The call stack is 2 call(s) deep:
Function/method: factorial(), Local variables: {'num': 4}
Function/method: factorial(), Local variables: {'num': 3}

The call stack is 3 call(s) deep:
Function/method: factorial(), Local variables: {'num': 4}
Function/method: factorial(), Local variables: {'num': 3}
Function/method: factorial(), Local variables: {'num': 2}

The call stack is 4 call(s) deep:
Function/method: factorial(), Local variables: {'num': 4}
Function/method: factorial(), Local variables: {'num': 3}
Function/method: factorial(), Local variables: {'num': 2}
Function/method: factorial(), Local variables: {'num': 1}

You can also call the showcallstack.getcallstack() function to get this output as a list of strings.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ShowCallStack-0.2.0.tar.gz (2.8 kB view details)

Uploaded Source

File details

Details for the file ShowCallStack-0.2.0.tar.gz.

File metadata

  • Download URL: ShowCallStack-0.2.0.tar.gz
  • Upload date:
  • Size: 2.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.9.0

File hashes

Hashes for ShowCallStack-0.2.0.tar.gz
Algorithm Hash digest
SHA256 35e508ae2d1665d74d05d2ad5d62c5b9b22b182c106bb0f3cbcc2cbf8b6100bf
MD5 c9d99c3af79ae078f0ca2b28125a323e
BLAKE2b-256 2681667aab76fb3b46bce88e68a1c6593c328d1277dc32a6d9c8bd372b4d8a4c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page