array in class

alefajnie devphyl at gmail.com
Tue May 13 06:04:06 EDT 2008


class A:
   this_is_original_variable_only_for_one_inctance = 0

   def __init__(self, v):
   self.this_is_original_variable_only_for_one_inctance = v


class B:
  this_is_common_for_all_instances = []

  def __init__(self, v):
    self.this_is_common_for_all_instances.append(v)


----------------
now I can create some instances of B, but all of them have the same
array, why

if I use append for b1.this_is_common_for_all_instances, the b2, b3
will have been changed that array.
(where bi is instance of B)
but changes on this_is_original_variable_only_for_one_inctance works
fine

why it does that?
and how create array in class - normal array, "private variable"



More information about the Python-list mailing list