This is the code I written so far, and the point with the program is to read 20 people from a file and then assign them their attributes, then normalise their values from a input given by the user.
class One:
def __init__(self):
self.attrOne = ()
self.attrTwo = ()
self.attrThree = ()
self.attrFour = ()
self.attrFive= ()
self.attrSix = ()
self.attrSeven = ()
self.attrEight = ()
self.attrNine = ()
class Two:
def __init__(self):
self.allPersons = []
def importFromList(self, filename):
file= open(filename, "rU")
for line in file:
partOfList = line.split()
x = Partner()
x.attrOne = partOfList[0]
x.attrTwo = partOfList[1]
x.attrThree = partOfList[2]
x.attrFour = partOfList[3]
x.attrFive = partOfList[4]
x.attrSix = partOfList[5]
x.attrSeven = partOfList[6]
x.attrEight= partOfList[7]
x.attrNine = partOfList[8]
self.addPerson(x)
file.close()
def addPerson(self, x):
self.allPersons.append(x)
What I wonder is how to loop through the attributes of the persons that is placed in allPersons list and then compare them against eachother to find out the max value. This is what I tried so far, but I can't get it to work
def getMaxValue(self):
o = One()
for eachPartner in self.allPartners:
maxValuesAttrOne = max(O.attrOne))
All help will be appreciated, and I'm open for new solutions, also I imagine the importFromList method is not the most effective one, so if you got any objections I'm willing to listen and learn!
attrOnethroughattrNineinstead of, say, a single attribute which is a list of 9 values, or a dict mapping 9 names to values? - abarnertOnehave 9 attributes all set to an empty tuple, whilePartnerhas 9 attributes with the same names each set to a string? That seems like a recipe for confusion… - abarnertself.name = nameinstead of storing an empty tuple and then forgetting the name! But if you don't have a name, using()as an "initializing value" for an attribute meant to hold strings is very weird. Either don't initialize it at all (so there will be noattrOneattribute until you have a real value to store there—which is perfectly fine; you're allowed to add new attributes to objects after__init__), or initialize it to''orNone. - abarnertdictidea… if these are real attributes likenameandage, you probably don't want to do that. When you have a bunch of attributes with names likeattrOneandattrTwo, that implies that you're going to be writing code that tries to read an attribute chosen dynamically based on some index or something, and that's almost always a bad idea. It doesn't sound like you have any intention of doing anything like that. So, don't worry about that part. - abarnert