M
Maksim Kasimov
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
__data1: []
__data2: []
__data1: [2005, 8, 9, 16, 25, 18, 1, 221, 1]
__data2: [2005, 8, 9, 16, 25, 18, 1, 221, 1]__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]
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
__data1: []
__data2: []
__data1: [2005, 8, 9, 16, 25, 18, 1, 221, 1]
__data2: [2005, 8, 9, 16, 25, 18, 1, 221, 1]__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]