Python: Objects Have The Same Value?
I have a csv file which looks like this: 1;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0 2;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0 3;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0 ... 16000;0;0;0;0;0;0;0;0;0;0;0
Solution 1:
You need to move the definition of datensatz
from the class. Right now it's a class variable shared across all instances, so it holds the last row created.
Try:
classDatensatz:def__init__(self):
self.datensatz = ['','','','','','','','','','','','','','','','','','']
or better:
classDatensatz:
def__init__(self, row):
self.datensatz = row[:] # [:] is making a shallow copy of the list.defreadCSV():
withopen(path, 'r', encoding = 'iso-8859-15') as csvfile:
spamreader = csv.reader(csvfile, delimiter=';')
for row in spamreader:
#First printprint(Datensatz(row).datensatz[0])
dLst.append(Datensatz(row))
for item in dLst:
#second printprint(item.datensatz[0])
Post a Comment for "Python: Objects Have The Same Value?"