0

How do I make the python shell print/show the commands that is done exactly when its done?

For an example is, If my python file contains:

variable = something
IF variable == something:
    print “hello”

So when I run the file in python shell, I want it to print all the commands as they are executed.

Devesh Kumar Singh
  • 20,259
  • 5
  • 21
  • 40
Ahoijer
  • 11
  • 1
  • 1
    a debugger will highlight the code for you at runtime. – Mohammed Janati Idrissi Apr 30 '19 at 10:33
  • Welcome to the Stack! Like @MJanaTil suggested, you could use a line debugger to step through your code line by line. For example, Python comes with pdb as an in-built debugger. A somewhat intuitive tutorial for pdb is provided by DigitalOcean here: https://www.digitalocean.com/community/tutorials/how-to-use-the-python-debugger – Jizhou Yang Apr 30 '19 at 10:34
  • Possible duplicate of [How to step through Python code to help debug issues?](https://stackoverflow.com/questions/4929251/how-to-step-through-python-code-to-help-debug-issues) – Gino Mempin Apr 30 '19 at 10:41

1 Answers1

3

You can use the built-in trace module

python3 -m trace --trace file.py
Ron Serruya
  • 3,988
  • 1
  • 16
  • 26