Hello. I'm trying to create a class to represent products which includes a list of volume based pricing and sets the first of these as the unit price:
def __init__(self, RatePlanID): self.id = RatePlanID self.name = RatePlans.toggleids[self.id] self.pricing = RatePlans.pricebreaks[self.name] self.unitprice = RatePlans.pricebreaks[self.name][0] This code gives an IndexError: ... self.unitprice = RatePlans.pricebreaks[self.name][0] IndexError: list index out of range However, the same code with the last line changed to: self.unitprice = RatePlans.pricebreaks[self.name][:1] seems to work OK, although, I can't process it further and extract the second element of the pair. The list I'm trying to process is: [(1, 21.0), (100, 19.6), (250, 18.4), (500, 17.6), (1000, 16.7), (2500, 14.7), (10000, 13.7)] and a cut and paste into the IDLE GUI let's me process it exactly as I expect (including picking the second element of the tuple, the price rather than the volume level): >>> [(1, 21.0), (100, 19.6), (250, 18.4), (500, 17.6), (1000, 16.7), (2500, 14.7), (10000, 13.7)][0][1] 21.0 What am I missing about the class definition that won't let me put this class in the init call? Thanks, Leo. _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor