Recently i encountered an error in python script.
And i was searching some way to debug the script.
Luckily i got a way to do so by using python debugger(pdb) option with python command and traversing the program statement using “n” i.e. next statement.
Lets see how to do this.
Debugging a python script “operator.py”
Here i have created a script called opertor.py and facing an issue in second line where i defined a variable “y” having string “ngelinux” without quotes like below:
Hence it assumed “ngelinux” to be a variable instead of a string and thrown an error.
I have debugged the script like below.
user@ngelinux$ python -m pdb ./operator.py > /Users/saket1447583/python/operator.py(2)
() -> x=2 (Pdb) (Pdb) (Pdb) n > /Users/saket1447583/python/operator.py(3) () -> y=ngeLinux (Pdb) n NameError: "name 'ngeLinux' is not defined" > /Users/saket1447583/python/operator.py(3) () -> y=ngeLinux (Pdb) q user@ngelinux$