
-----------------------------------
Zren
Mon Mar 01, 2010 9:13 pm

Class Instances
-----------------------------------
class Map:
    def __init__(self, w=100, h=100):
        self.w = w
        self.h = h
        self.camera = Camera(self.w, self.h)
        self.newObject(self.camera)
        self.objs = 

My question is that if I call self.camera and modify it's variables, would it affect the same instance of Camera as the one inside the self.objs list?

-----------------------------------
DtY
Mon Mar 01, 2010 10:01 pm

RE:Class Instances
-----------------------------------
Short; yes

Long; yes, everything in python are references. When you create a new object, it stores a reference to the newly created object in that variable.

a = 

Because `b` and `a` are references to the same object, changing `b` changes `a`, and vice versa.

Same thing happens when calling a function, a local reference to that variable is made.

There are just two things to look out for:

a = 

This may appear to go against what I just said, but what is happening is that when you say b = >>> a = 

Just to note, the ellipses in that example denote a self reference, it would fall into infinite recursion if it tried to expand it, so it's smart about it.

-----------------------------------
Zren
Mon Mar 01, 2010 10:11 pm

RE:Class Instances
-----------------------------------
Thanks for the last note lol, I was about to try it. And thanks for the long explanation as well.
