How to track our python script files.

Abhishek Mishra
3 min readMay 18, 2020

Today python is one of the popular languages in computer science. But do you think about that how you track our python scripts “line by line” with the help of either command or some selected keys? Before discussing on python, let’s have some focus on the “C” language. In “C” language the files are compiled by compiler either it is “Turbo c” or any other which you want to be used in your system. In “C” language any “C” file is compiled with the sequences of a bit of line, with the help of either “F7” or “fn+F7”.

Now we have come back to python. As you all know that python is scripting, interpreted language. Then how we can check the python file like “C” programming language?

Don’t worry about that because that is one way to track our Python code line by line:-

Open your cmd(command prompt)and write the command given below:-

python -m trace — trace filename.py

One thing which should be noticed that your cmd must be in the same directory in which that python file exists. For that you can open that folder and press “shift+right click(mouse)”, then select “open command window here”,ooh..you will be on target directory, now you can use the python command which is on above.

Let’s take an example….

First, we create required python file(here “add.py” is considered)

add.py file

Now press “F5” or “shift+F5” after saving the file (In this case directory is desktop). Now the output is given below…

the output of “add.py” file

Now its turn to tracing our python file. Open cmd on desktop(the directory in which python file exists), then write the command “python -m trace — trace add.py”. Now you will able to see our traced python file. The output looks like as below:-

Tracing output

Now one thing is a notice that maybe the file is using some modules like NumPy, Keras, pandas e.t.c, then the tracing output is very complex because it also traced their embedded code. Let’s see an example…

Write this in a new python file and try to trace this one line with the help of command, then you will get an unexpected result but that result is correct.

--

--

Abhishek Mishra

System Engineer-TCS | COMPUTER SCIENCE ENGINEER | I love Python 🐍🐍😀