eAx
eAx

Reputation: 39

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 know if it has a tracing feature.

Any tips or resources that are newbie friendly on this issue?

Thanks very much in advance!

Upvotes: 3

Views: 5985

Answers (2)

lukewarm
lukewarm

Reputation: 857

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.

Upvotes: 1

ospahiu
ospahiu

Reputation: 3525

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

Upvotes: 2

Related Questions