I am in problem4 of pset 9 and for some reason my function only ends up returning the last element instead of the whole class. This is the code I am using in the next post
def readShapesFromFile(filename): """ Retrieves shape information from the given file. Creates and returns a ShapeSet with the shapes found. filename: string """ ## TO DO inputFile = open(filename) shapeD = {} group = None for line in inputFile: print 'group up', group stripped = line.strip('\n') splitted = stripped.split(',') splitted[1] = float(splitted[1]) shape = splitted[0] shape = capitalize(shape) values = splitted[1:] group = ShapeSet() if shape == 'Circle': group.addShape(Circle(values[0])) if shape == 'Square': group.addShape(Square(values[0])) if shape == 'Triangle': group.addShape(Triangle(values[0], values[1])) print 'group', group print 'group outside loop', group return group
still on ps8 but once I'm doing ps9 I'll get back to you maybe today even...
You create a new ShapeSet() in every loop iteration, thus losing whatever you've stored in it till that moment.
Thanks! I don't know what was I thinking :(
@knowak :gave you a medal ~ thought you deserved it for that one.
Join our real-time social learning platform and learn together with your friends!