Debugging with a Debugger


Break points

  1. Insert breakpoint
  2. Press Debug
  3. Program runs until breakpoint and stops (before executing the line of code)
  4. Stack Data gives the current values for all variables (Local vs. Global)
  5. Pressing Debug again continues to the next breakpoint


Conditional breakpoints (Pro and other debuggers)

Example - Pleistocene Overkill



  1. Run, get error
  2. Run debugger, highlights line with error, show Stack Data
  3. Fix missing underscores
  4. Restart
  5. Lots of nan’s, likely a problem with the data so look at it
  6. Fix missing dtype=None and rerun
  7. That fixed one of our problems, but now too many lines, not easy to see, so
  8. Set a break point at start of loop
  9. Demo step in/over/out
  10. Use unique not actual


import numpy as np

def mean_mass(masses):
    """Return the mean of a list of masses"""
    mean_mass = np.mean(masses)
    return masses

all_data = np.genfromtxt('MOMv3.3.txt', delimiter='\t', dtype=None,
                          names=['continent', 'status', 'order', 'family',
                                 'genus', 'species', 'log10mass', 'mass', 'ref'])

continents = all_data['continent']
status = all_data['status']
masses = all_data['mass']

results = []
for continent in continents:
    extinct_masses = masses[(status=='extinct') & (continents==continent)]
    extant_masses = masses[(status=='extant') & (continents==continent)]
    avg_extinct_mass = np.mean(extinct_masses)
    avg_extant_mass = np.mean(extant_masses)
    diff = avg_extant_mass - avg_extinct_mass
    results.append([continent, avg_extantmass, avg_extinctmass, diff])

for line in results:
    print line