I have two classes. One is Fruit, with various attributes, and one is FruitBasket, which holds the fruit. I want to add the fruit to the basket, which is very simple. However, I can't have more than one of each type of fruit in the basket. So in append, I need to iterate through the fruit basket, before appending. No problem, right?
For me...WRONG! I cannot figure out how to access Fruit's getType() function. It's really easy if they are combined in one file, but this is an extremely simplified version of a larger project I am working on, and all of the files are separated.
So lets say fruit.py is located in the Project1 package, in the production folder. So I would add the appropriate import statement in fruitbasket.py. No problem.
class Fruit(object): def __init__(self, typeOfFruit, number, color): self.theType = typeOfFruit self.theNumber = number self.theColor = color def getType(self): return self.theType
import Project1.production.fruit as fruit class FruitBasket(object): def __init__(self): #the basket is empty upon initialization self.theBasket =  def __iter__(self): # make iterable return iter(self.theBasket) def addFruit(self, fruit): self.theBasket.append(fruit)
firstFruit = Fruit('apple', 2, 'red')
basket = FruitBasket()
secondFruit = Fruit('banana', 3, 'yellow')
for afruit in basket: