- 论坛徽章:
- 0
|
1 class Food:
2 def __init__(self,name):
3 self.name=name
4
5 class Employee:
6 def takeOrder(self,foodName):
7 return Food(foodName)
8
9 class Customer:
10 def __init__(self):
11 print 'in customer init'
12 self.food=None
13 def placeOrder(self,foodName,empoyee):
14 self.food=employee.takeOrder(foodName)
15 def printFood(self):
16 print self.food.name
17
18 class Lunch:
19 def __Init__(self):
20 self.custom=Customer()
21 self.empl=Employee()
22
23 def order(self,foodName):
24 self.custom.placeOrder(foodName,self.empl)
25 def result(self):
26 self.cust.printFood()
27
28 if __name__=='__main__':
29 x=Lunch()
30 x.order('burritors')
31 x.result()
32 x.order('pizza')
33 x.result()
34
~
python lunch.py
Traceback (most recent call last):
File "lunch.py", line 30, in ?
x.order('burritors')
File "lunch.py", line 24, in order
self.custom.placeOrder(foodName,self.empl)
AttributeError: Lunch instance has no attribute 'custom'
麻烦大家帮我看看,为什么总报错呀,谢谢了。 |
|