Class initialization

Costin Gamenț costin.gament at gmail.com
Sun Aug 8 11:45:53 EDT 2010


Thanks a lot. I'll try give it a go and see if it helps.

On Sun, Aug 8, 2010 at 6:28 PM, Tim Harig <usernet at ilthio.net> wrote:
> It is not so much using __init__() that makes the difference as it what
> scope the variables are assigned to.  If you define them as you where, then
> the variables are associated with the class object itself.  If the variable
> is a mutable type, and you change it in one instance, it actually changes
> it in the class object which means it also changes for all of the
> instances.
>
> I used the constructor because it gives me a reference to the newly created
> instance object "self".  I then assign the variables to self, which
> assignes them to the newly created instance object.  Then each instance has
> its own separate a and b variables that will not change when the variables
> are changed inside of another instance object.



More information about the Python-list mailing list