I currently have pdb imported in the calibrate function in a large python class called Machine.  In another file, I create an instance of this class and run calibrate.  I'm trying to access self.r_error which is a dictionary that points to a function, and it definitely exists and is normally recognized by the shell, but for some reason I can't iterate through it in a list:
(Pdb) self
<direct_simulation.Machine object at 0x033D7110>
(Pdb) self.r_error["xRx"](5)
1.9352496986596831e-10
(Pdb) y2 = [self.r_error["xRx"](i) for i in x]
*** NameError: name 'self' is not defined
What's going on?
Here are some parts of the code that may or may not be relevant:
direct_simulation.py:
from collections import defaultdict
import numpy as np
class Machine(object):
    ...
    def _init_error(self):
        get5rands = lambda: [np.random.normal(0,1) for _ in range(5)]
        def rot_error_curve(a,b,c,d,e):
            def curve(x):
                ...
                (build a curve over the real numbers with a,b,c,d, and e)
                ...
            return curve
        self.r_error = defaultdict(lambda: rot_error_curve(*get5rands()),{})
    ...
    def calibrate(self):
        ...
        (things happen that create self.r_error["xRx"])
        ...
        import pdb;pdb.set_trace()
dsim_test.py:
import direct_simulation as ds
...
def do_cal():
    global mm
    mm = ds.Machine()
    mm.calibrate()
    ...
if __name__ == "__main__":
    do_cal()
And then in the shell, I ran python3 -i dsim_test.py.  There weren't any errors, but self remains undefined precisely whenever it's in a list.
