Jul-22-2017, 01:23 PM
Hello all,
I'm trying to create a list of different objects using a loop.
I expect to get a list of different objects. But, in fact, I get a list of same objects.
I'm trying to create a list of different objects using a loop.
I expect to get a list of different objects. But, in fact, I get a list of same objects.
path = "C:/SomethingRandom/file.txt" myList = [] with open(path, 'r', 8192, 'utf8') as input_file: while True: line = input_file.readline() if len(line) != 0: classObject = className() classObject.getData(line) myList.append(classObject) del classObject else: print("End of file!") breakSo... As I've checked using printf(), in every loop iteration string "line" changes it's value. But myList containts as many copies of first object (created using first "line"), as many lines my .txt file has. I have no idea why it happens.