Could you please help me.How to use this module for debugging the application functionality thru UI as entry point?
Thanks
PSB
if you are using a UI, your UI should come with debugging facilities. Even Pythonwin or IDLE does a bit of debugging for you. this pdb module is sort of command line debugging. Here's a simple guide on how to use it.
imagine you have this code:
-
import pdb,sys
-
def afunc():
-
a = 1
-
b = 2
-
c = a+b
-
return a,b,c
-
pdb.set_trace() #put the trace starting here.
-
a = 100
-
b = 200
-
d = afunc()
-
sys.exit()
-
output:
-
# ./test1.py
-
> /test/test1.py(13)?()
-
-> a = 100
-
(Pdb) n
-
> /test/test1.py(14)?()
-
-> b = 200
-
(Pdb) n
-
> /test/test1.py(15)?()
-
-> d = afunc()
-
(Pdb) s
-
--Call--
-
> /test/test1.py(6)afunc()
-
-> def afunc():
-
(Pdb) n
-
> /test/test1.py(7)afunc()
-
-> a = 1
-
(Pdb) n
-
> /test/test1.py(8)afunc()
-
-> b = 2
-
(Pdb) n
-
> /test/test1.py(9)afunc()
-
-> c = a+b
-
(Pdb) n
-
> /test/test1.py(10)afunc()
-
-> return a,b,c
-
(Pdb) p c
-
3
-
(Pdb) n
-
--Return--
-
> /test/test1.py(10)afunc()->(1, 2, 3)
-
-> return a,b,c
-
(Pdb) n
-
> /test/test1.py(17)?()
-
-> sys.exit()
-
(Pdb) p d
-
(1, 2, 3)
-
(Pdb) n
-
SystemExit: None
-
> /test/test1.py(17)?()
-
-> sys.exit()
-
once the script executes, you go to the debug prompt. type 'h' for a list of commands you can use to debug. most common ones I use are s,l, h, p , n. 'l' shows you where you are now, 'p' prints out values of variables , 'n' means next step. 's' means if you hit a function, you step into that function.
Noticed when i hit the afunc() functoin, i use s to step into it. then i continue with 'n' . when when it reaches c=a+b, i hit 'n' to execute it, then i do a 'p c' to print the value of c. After the return , i did another 'p d' to print the value of the afunc(), which is a tuple. Well, this is very short, please go experiment it yourself. there's always google if you need more resources.