Insert this line in your code where you suspect a bug to be hidden:
import pdb; pdb.set_trace()
-> this causes the script to stop and a debug console pops out.
l -> to see a short listing of code of the place you're currently executing
dir(object_name) -> to display object's methods & fields