I have a file with the attributes for an object on each line. I want to take the attributes, separated by spaces, and add them to my object. I want the objects in a list but I can't get it to work. I have put a comment next to the line that doesn't do what I think it should be able to do. Alternatively if I just pass the words list, it stores the entire list in the first attribute of the object.
class Brick(object):
def __init__(self, xopos=None, yopos=None, xcpos=None, ycpos=None, numb=None, prop=None):
self.xopos = xopos
self.yopos = yopos
self.xcpos = xcpos
self.ycpos = ycpos
self.numb = numb
self.prop = prop
bricklist = []
with open('data.txt', 'r') as f:
data = f.readlines()
for line in data:
words = line.split()
bricklist.append(Brick.xopos(words[0])) #line that doesnt work
for i in range(len(bricklist)):
print (bricklist[i].xopos)
the data is simply
1 13 14 15 16 17
2 21 22 23 24 14
3 3 4 5 6 7
4 1 1 1 1 1
5 5 6 4 1 1
6 5 6 8 4 2
7 4 9 7 5 6
I am very new to python, and I am finding alot of my ideas for implementing things just don't work so any help would be much appreciated.