Error in attaching node to a object

Here is the part of the code that’s showing the error:

        self.object.reparentTo(render)

        self.parentnode = render.attachNewNode('camparent')
        self.parentnode.reparentTo(object) 
        self.parentnode.setEffect(CompassEffect.make(render))

The Error

self.parentnode.reparentTo(object)
TypeError: NodePath.reparent_to() argument 1 must be panda3d.core.NodePath, not type

How do I correct it?

I see two issues here, I believe:

First, “object” happens to be the name of a base-class that Python provides. Thus when you attempt to reparent to “object”, Python things that you’re trying to operate on said class.

And second, this is happening because you haven’t included “self.” before “object” in your call to “reparentTo”. Thus the program isn’t looking for the variable named “object” that belongs to the class referenced by “self”, but rather for something by the same name in a more general scope. That scope might include things like local variables–and default classes provided by Python.