Skip to content Skip to sidebar Skip to footer

How Do I Trace My Python Program From Start Of Execution To Finish?

I have a function written in python, and I want to inspect how it runs step by step from start to finish. How do I go about doing this? I am using PyCharm as an IDE, but I don't kn

Solution 1:

What you're looking for is a profiler. Luckily, PyCharm is really powerful and comes with a wealth of debugging/profiling tools.

Solution 2:

If you're running your code within PyCharm, simply set a breakpoint on the first line within the function you wish to examine, then step through it using their interface.

If you're running your code via the commandline, I highly recommend familiarizing yourself with Python's debugging module, pdb. All you need to do to examine your function is temporarily add the line:

import pdb;pdb.set_trace()

.. as the first line of your function. When you run it and it hits this line, you can step through the execution on the commandline using simple directives like 'n' for next line.

Post a Comment for "How Do I Trace My Python Program From Start Of Execution To Finish?"