Skip to content

Python print stack trace without exception

  • by

Use traceback.print_stack to print stack trace without exception In Python. This module provides a standard interface to extract, format, and print stack traces of Python programs.

Python print stack trace without exception

Simple example code.

import traceback

def func1():
    def func2():




Python print stack trace without exception

Here’s a way you can get some trace info:

def what():
    return 3

def hey():
    return what()

def yo():
    return hey()

import trace
tracer = trace.Trace()"yo()")
r = tracer.results()


 --- modulename: main, funcname: <module>
<string>(1):  --- modulename: main, funcname: yo     return hey()
 --- modulename: main, funcname: hey     return what()
 --- modulename: main, funcname: what     return 3

Do comment if you have any doubts or suggestions on this Python Traceback topic.

Note: IDE: PyCharm 2021.3.3 (Community Edition)

Windows 10

Python 3.10.1

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading