PVectors in Class Objects

Thanks, that did it! As the ‘sub_vec’ method is called once per frame, that’s where I put the static method, rather than ‘init’. Here’s the code that works as intended:

class Foo:
    def __init__(self, targ_pos, mis_pos):
        self.targ_pos = targ_pos
        self.mis_pos = mis_pos
        self.l_o_s = PVector()
    def sub_vec(self, target_pos):
        # temp_vec = mis_pos.copy() # uncomment to clear error
        # self.l_o_s = temp_vec.sub(self.targ_pos) # uncomment to clear error
        # self.l_o_s = self.mis_pos.sub(self.targ_pos) # commented to try static PVector
        self.l_o_s = PVector.sub(self.mis_pos,(self.targ_pos)) 
        return self.l_o_s

foo = Foo(targ_pos, mis_pos)

def draw():
    global i
    vec = foo.sub_vec(targ_pos)
    print('targ_pos ', targ_pos)
    print('mis_pos ', mis_pos)
    print('vec ', vec)

Your reply led me to Prof Schiffman’s excellent tutorial, which helped me a lot.