don't understand instanse creation

Maksim Kasimov maksim.kasimov at gmail.com
Tue Aug 9 09:39:51 EDT 2005


Hello,

i have a class, such as below.
when i try to make instances of the class,
fields __data1 and __data2 gets different values: __data1 behaves like private field, __data2 - like static
which is the thing i've missed?

thanks for help.

====================================================


import time
class my:

     __data1 = []
     __data2 = []

     def __init__(self):

         print "__data1: ", self.__data1
         print "__data2: ", self.__data2

         for i in time.localtime():
             self.__data2.append(i)
         self.__data1 = self.__data2[:]

         print "__data1: ", self.__data1
         print "__data2: ", self.__data2


====================================================


Python 2.2.3
FreeBSD

 >>> m1 = my.my()
__data1:  []
__data2:  []
__data1:  [2005, 8, 9, 16, 25, 18, 1, 221, 1]
__data2:  [2005, 8, 9, 16, 25, 18, 1, 221, 1]
 >>>
 >>>
 >>> m2 = my.my()
__data1:  []
__data2:  [2005, 8, 9, 16, 25, 18, 1, 221, 1]
__data1:  [2005, 8, 9, 16, 25, 18, 1, 221, 1, 2005, 8, 9, 16, 25, 25, 1, 221, 1]
__data2:  [2005, 8, 9, 16, 25, 18, 1, 221, 1, 2005, 8, 9, 16, 25, 25, 1, 221, 1]





-- 
Best regards,
Maksim Kasimov
mailto: maksim.kasimov at gmail.com



More information about the Python-list mailing list