Debugging python...

To debug a specific python script, start by inserting the following in to your .py file:

import pdb; pdb.set_trace()

These commands allow you to step through the code from the point of where pdb.set_trace() is placed in your script.

p \<object> - print the content of an object
n - next line
c - continue through rest of script, to next break point, or next pdb.set_trace()
s - step in to function/routine and make edits or view
var = 'new value'

start with this script.

#!/bin/env python
import pdb

var_0 = 'day'
var_1 = 'night'

print '   var_0: %s\n   var_1: %s' % (var_0, var_1)
#pdb.set_trace()

print 'from %s in to %s and back again.' % (var_0, var_1)

run it with the pdb line commented and you get this.

$ ./day.py
   var_0: day
      var_1: night
      from day in to night and back again.

Now uncomment the pdb line and run it again.

$ ./day.py
 var_0: day
 var_1: night
> /home/msnow/bin/day.py(10)()
-> print 'from %s in to %s and back again.' % (var_0, var_1)
(Pdb) n
 from day in to night and back again.
--Return--
> /home/msnow/bin/day.py(10)()->None
-> print 'from %s in to %s and back again.' % (var_0, var_1)
(Pdb) n
$

This shows you part of the program running, then dropping in to the debugger just before the area of code you want to look at.
Now we will change the values assigned to val_0 and val_1 withough editing the file.

$ ./day.py
 var_0: day
 var_1: night
> /home/msnow/bin/day.py(10)()
-> print 'from %s in to %s and back again.' % (var_0, var_1)
(Pdb) var_0
'day'
(Pdb) var_1
'night'
(Pdb) var_0 = 'morning'
(Pdb) var_1 = 'evening'
(Pdb) n
from morning in to evening and back again.
--Return--
> /home/msnow/bin/day.py(10)()->None
-> print 'from %s in to %s and back again.' % (var_0, var_1)
(Pdb) n
$