class rating(): def __init__(self, user, item, rating): self.user = user self.item = item self.rating = rating def __str__(self): return str(user) + " " + str(item) + " " + str(rating) def __repr__(self): return str(user) + " " + str(item) + " " + str(rating) data = open('data.dat').readlines() records = () in data: user, item, rating = i.split() r = rating(user, item, rating) records += (r,) print records
data = [a, b, c]
, i'd expect records
have (<record> a, <record> b, <record> c)
. instead contains (<record> c, <record> c, <record> c)
?
you not using class attributes, global variables have defined chance.
return str(user) + " " + str(item) + " " + str(rating)
should like
return str(self.user) + " " + str(self.item) + " " + str(self.rating)
Comments
Post a Comment