Verifying Variable value

Krishnan Shankar i.am.songoku at gmail.com
Wed Aug 14 07:29:04 EDT 2013


Hi Chandan,

Python has built-in module called pdb which can be used for debugging.
Importing it in the right place will be like setting break point in code
and will change the execution to debugging mode. We can use different
debugging commands ((n)ext, (c)ontinue, (s)tep  etc) to evaluate through
the code. Below is the link to module,

http://docs.python.org/2/library/pdb.html

We can run this code in the following way "python -m pdb filename.py" to
run it in pdb debugging mode. Else import pdb and set the trace at right
place like below.

For example
=========
def method()
  import pdb;pdb.set_trace()   <<<----------  import and set_trace()
  a = 20
  b =30
  c =  a + b

method()

While running you will get pdb prompt to debug the code line by line. The
execution will be in user's hands.  Like below,

> c:\users\krishnan\desktop\test.py(3)method()
-> a = 20
(Pdb) n
> c:\users\krishnan\desktop\test.py(4)method()
-> b =30
(Pdb) n
> c:\users\krishnan\desktop\test.py(5)method()
-> c =  a + b
(Pdb) n
--Return--
> c:\users\krishnan\desktop\test.py(5)method()->None
-> c =  a + b
(Pdb) c

You can explore the module and find it useful for debugging. I hope this
helps

Regards,
Krishnan


On Wed, Aug 14, 2013 at 3:12 AM, chandan kumar <chandan_psr at yahoo.co.in>
wrote:
Hi ,

Is there a way to validate variable values while debugging any python
code.Run below example  in debugging mode and i would like to know the
value of c (I know print is an option) with any other option other than
printing.
In C# or some other tools we can verify each statement and values. Is there
way to check each statement in python code like in c#.

Ex:
def method()
  a = 20
  b =30
  c =  a + b


Best Regards,
Chanadn

--
http://mail.python.org/mailman/listinfo/python-list
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20130814/be71f1ca/attachment.html>


More information about the Python-list mailing list