Question on classes in Python
I am currently working on python and I just met a case which I find hard to understand:
Instance1 = class1 ()
Instance2 = Instance1.class2 ()
I adapted the trick (in fact it comes from panda 3D)
My question:
The 2nd row can really exist, if yes what is it (I do not understand the "Instance1.class2 ()")
I specify my problem a little, giving you the original in Panda 3D
Code:
# Load the panda actor, and loop its animation
pandaActor = Actor.Actor("models/panda-model",{"walk":"models/panda-walk4"})
pandaActor.setScale (0.005,0.005,0.005)
pandaActor.reparentTo (render)
pandaActor.loop ("walk")
#Create the four lerp intervals needed to walk back and forth
pandaPosInterval1= pandaActor.posInterval(13,Point3(0,-10,0), startPos=Point3(0,10,0))
pandaPosInterval2= pandaActor.posInterval(13,Point3(0,10,0), startPos=Point3(0,-10,0))
pandaHprInterval1= pandaActor.hprInterval(3,Point3(180,0,0), startHpr=Point3(0,0,0))
pandaHprInterval2= pandaActor.hprInterval(3,Point3(0,0,0), startHpr=Point3(180,0,0))
Actor is a class, so pandaActor is an instance of this class (line 2)
What I can not understand is:
pandaPosInterval1 = pandaActor.posInterval (........)
posInterval is also a class, I do not therefore: pandaActor.posInterval (........)
Practically, this I have no problem, I understand the trick, but at the theoretical level (pure Python), I do not know what this is.
Re: Question on classes in Python
look at the panda code ...
But there is much chance that Actor.posInterval is a method that simply return an instance of a class named Interval .
Re: Question on classes in Python
Thank you for your reply, but the doc panda3d (reference), posInterval is listed in the classes and not methods! Hence my interrogation!
Re: Question on classes in Python
PosInterval != posInterval
The case is important.
I had a quick look on the doc panda3d and I did not find a method posInterval.
Is the code that you gave run the latest version of panda?
Re: Question on classes in Python
Sorry for the box, it is PosInterval, and it is well documented in the classes (nothing in the functions and nothing in the methods) when my interrogation this is what: instance2 = Instance1.class2 (... )?
Also, this is the last version panda3D (software and doc)
Re: Question on classes in Python
There is no "instance2 = instance1.class2 ()", it does absolutely nothing to say. There is just instance2 = instance1.method ()