Connecting Tech Pros Worldwide Help | Site Map

Facing problem with Debugging with UI

Needs Regular Fix
 
Join Date: Feb 2007
Posts: 438
#1: Apr 16 '07
Hi,

I am not able to debug the application,when I have integrated UI with the application modules.

Whether I have to set/activate any options to debug the application code?

Thanks in advance
PSB
bartonc's Avatar
Moderator
 
Join Date: Sep 2006
Location: Minden, Nevada, USA
Posts: 6,400
#2: Apr 16 '07

re: Facing problem with Debugging with UI


Quote:

Originally Posted by psbasha

Hi,

I am not able to debug the application,when I have integrated UI with the application modules.

Whether I have to set/activate any options to debug the application code?

Thanks in advance
PSB

Honestly, most python programmers just throw in print statements for debugging. With a gui, you could also pop up a dialog with the state info that you are interested in.
Needs Regular Fix
 
Join Date: Feb 2007
Posts: 438
#3: Apr 16 '07

re: Facing problem with Debugging with UI


So ,We cannot debug line by line and check for the variable values.To get this details we have to use "print" statement .

-PSB
bartonc's Avatar
Moderator
 
Join Date: Sep 2006
Location: Minden, Nevada, USA
Posts: 6,400
#4: Apr 17 '07

re: Facing problem with Debugging with UI


Quote:

Originally Posted by psbasha

So ,We cannot debug line by line and check for the variable values.To get this details we have to use "print" statement .

-PSB

You can do it. It's just that PythonWin never worked very well for me and IDLE doesn't like GUI debugging at all.
I remember reading in the help on PythonWin that it has an option for GUI debug mode.

Using print just seems to be the quickest and most practiced way of doing debugging. (For example, I've been using Boa Constructor for over 6 months - while learning wxPython - and have never even tried the debugger.)
Expert
 
Join Date: Apr 2006
Posts: 512
#5: Apr 17 '07

re: Facing problem with Debugging with UI


Quote:

Originally Posted by psbasha

So ,We cannot debug line by line and check for the variable values.To get this details we have to use "print" statement .

-PSB

yes , you can, using the pdb module.
Needs Regular Fix
 
Join Date: Feb 2007
Posts: 438
#6: Apr 17 '07

re: Facing problem with Debugging with UI


Could you please help me.How to use this module for debugging the application functionality thru UI as entry point?

Thanks
PSB
Expert
 
Join Date: Apr 2006
Posts: 512
#7: Apr 17 '07

re: Facing problem with Debugging with UI


Quote:

Originally Posted by psbasha

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:
Expand|Select|Wrap|Line Numbers
  1. import pdb,sys
  2. def afunc():
  3.      a = 1
  4.      b = 2
  5.      c = a+b
  6.      return a,b,c
  7. pdb.set_trace()  #put the trace starting here.
  8. a = 100
  9. b = 200
  10. d = afunc()
  11. sys.exit()
  12.  
output:
Expand|Select|Wrap|Line Numbers
  1. # ./test1.py
  2. > /test/test1.py(13)?()
  3. -> a = 100
  4. (Pdb) n
  5. > /test/test1.py(14)?()
  6. -> b = 200
  7. (Pdb) n
  8. > /test/test1.py(15)?()
  9. -> d = afunc()
  10. (Pdb) s
  11. --Call--
  12. > /test/test1.py(6)afunc()
  13. -> def afunc():
  14. (Pdb) n
  15. > /test/test1.py(7)afunc()
  16. -> a = 1
  17. (Pdb) n
  18. > /test/test1.py(8)afunc()
  19. -> b = 2
  20. (Pdb) n
  21. > /test/test1.py(9)afunc()
  22. -> c = a+b
  23. (Pdb) n
  24. > /test/test1.py(10)afunc()
  25. -> return a,b,c
  26. (Pdb) p c
  27. 3
  28. (Pdb) n
  29. --Return--
  30. > /test/test1.py(10)afunc()->(1, 2, 3)
  31. -> return a,b,c
  32. (Pdb) n
  33. > /test/test1.py(17)?()
  34. -> sys.exit()
  35. (Pdb) p d
  36. (1, 2, 3)
  37. (Pdb) n
  38. SystemExit: None
  39. > /test/test1.py(17)?()
  40. -> sys.exit()
  41.  
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.
Reply