TypeError for unbound method
Cethric last edited by Cethric
With the following call
PhysicsCamera(euclid.Vector3(-10, 10, -10), yaw=30, pitch=-30)
I am recieving a
TypeError: unbound method of __init__() must be called with LookObject as first instance.
And this is the physics camera part
class PhysicsCamera(LookObject): def __init__(self, *args, **kwargs): LookObject.__init__(self, *args, **kwargs) self.camera_id = PhysicsWorld.add_camera(self) print "Camera ID:", self.camera_id
This is a new class that I am creating for my OpenGLES package.
Can someone please explain why this could be happening as this is exactly the same as how I normally subclass an object
Webmaster4o last edited by
At first look not really as when I instantiate I have passed
selfas the first paramater and use python2.x new objects ie
class x(object): pass
However thankyou for the response. For now I have do the long way around of just copying the class instead of instantiation.
JonB last edited by
Is it poseible you forgot the self when defining LookObject.init?
Are you able to instantiate a LookObject?
This is how I instantiate the LookObject
class PhysicsCamera(LookObject): def __init__(self, *args, **kwargs): LookObject.__init__(self, *args, **kwargs)
But this raises
TypeError unbound method __init__() must be called with LookObject as first argument (got PhysicsCamera instead).
I also noticed that when I run this from the python file it was created in
LightsCameras.py(New file yet to add it to repo) it works fine but when I use it from
main.pythen the above issue is raised
Further test show that it is just that file as I just tried to use a XMLModel object in it. When testing from
LightsCameras.pyit works fine but as soon as I test it from
main.pyan TypeError is raised. Is this a bug in python/pythonista or have I missed something. I will upload it to the repo.
Webmaster4o last edited by Webmaster4o
Will it ever be run from
main.pyin the module, or just from
It will be used in
main.pyhowever I always try to make it so that classes can be tested from their own file...
Webmaster4o last edited by
Right. Makes sense. (Btw typing this through SlideOver on my iPad and NodeBB does a great job adapting to the weird size.
ywangd last edited by
I have seen this type of error before. It is caused by the
reload()statements in your
Reload will define a new class object for the same class. To Python interpreter, this new class object is considered as a different class from the old class object. If you have a subclass instance of the old class object, it will not be compatible with the new class object. In your case, it is most likely that the
PhysicsCamerais still a subclass of the old
You could try replace
super(PhysicsCamera, self).__init__(*args, **kwargs). The
super()function should get the correct parent class. But it also means any changes to the parent class via reload are not honored.
@ywangd that has resolved the issue, thank you for the infomation about it