Class initialization

Costin Gament costin.gament at gmail.com
Sun Aug 8 10:14:08 EDT 2010


Thank you for your answer, but it seems I didn't make myself clear.
Take the code:
class foo:
  a = 0
  b = 0
c1 = foo()
c1.a = 5
c2 = foo()
print c2.a
5

Somehow, when I try to acces the 'a' variable in c2 it has the same
value as the 'a' variable in c1. Am I missing something?

On Sun, Aug 8, 2010 at 4:59 PM, Roald de Vries <downaold at gmail.com> wrote:
>
> Your problem probably is that a and b are class variables; c1 and c2 are
> different objects (in your terminology: they point to different instances).
>
> See http://docs.python.org/tutorial/classes.html#class-objects for more
> info.
>
> Cheers, Roald
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list