お世話になります。下記のコードを記述して学習していますが
AttributeErrorが出ます
原因がわかりません。
class Secretary:
def init(self):
self.appointment = {}
def request_appointment(self, when, who): if(when in self.appointment): return False else: self.appointment[when] = who return True def get_schedule(self): return str(self.appointment)
from secretary import *
class Manager:
def init(self):
self.sara = Secretary()
def check_schedule(self): schedule = self.sara.get_schedule() print(schedule) def get_secretary(self): return self.sara
class Client:
def init(self, name):
self.name = name
self.contact_point = None
def set_contact_point(self, contact_point): self.contact_point = contact_point def make_appointment(self, when): if(self.contact_point): is_success = self.contact_point.request_appointment(when, self.name) print(self.name + " could book? : " + str(is_success))
bob = Manager()
adam = Client('adam')
adam.set_contact_point(bob.get_secretary())
adam.make_appointment('10:30')
charles = Client('charles')
charles.set_contact_point(bob.get_secretary())
charles.make_appointment('11:30')
dag = Client('dag')
dag.set_contact_point(bob.get_secretary())
dag.make_appointment('10:30')
bob.check_schedule()
*************************
エラー内容↓↓↓↓↓↓↓
Traceback (most recent call last):
File "C:/Python27/2016_8.5.py", line 45, in <module>
adam.make_appointment('10:30')
File "C:/Python27/2016_8.5.py", line 38, in make_appointment
is_success = self.contact_point.request_appointment(when, self.name)
AttributeError: Secretary instance has no attribute 'request_appointment'
回答1件
あなたの回答
tips
プレビュー