I am new to creating a list of classes. Hence I checked out this website: http://www.daniweb.com/code/snippet390.html. However, I modified the code to check if a class with a particular has been created before.
My code works when I create the first class and append it to the list. However, subsequent creations and appending results in this error: "AttributeError : No __call__ method defined." Why is this so? Why does the program from the above link work but mine doesn't? How do I solve the problem?
Below are snippets of my code. If you require any other parts of it for further understanding, feel free to let me know.
Thanks a million!
My code works when I create the first class and append it to the list. However, subsequent creations and appending results in this error: "AttributeError : No __call__ method defined." Why is this so? Why does the program from the above link work but mine doesn't? How do I solve the problem?
Below are snippets of my code. If you require any other parts of it for further understanding, feel free to let me know.
Thanks a million!
Code:
class survey: def __init__(self,name,qn): self.name = name self.qn = qn self.ans_list=[] #array of integers self.mean='' self.sd='' self.median='' self.mode=[] #array of string def retrieve(self): debug = 'Survey name: ' + self.name + '\r\n' debug = debug + 'Qn: ' + self.qn + '\r\n' return debug
Code:
survey_no=0
surveylist=[]
while (1):
if content_list[2].lower()=='create':
name = content_list[3].lower() #SURVEY NAME
first_occur = content.find('"')+1
last_occur = content.rfind('"')
qn = content[first_occur: last_occur] #SURVEY QUESTION
reply_sms=''
for survey in surveylist:
if survey.name==name:
reply_sms = 'This survey already exists. '
print reply_sms
if reply_sms=='':
surveylist.append(survey(name, qn))
reply_sms = surveylist[survey_no].retrieve()
survey_no = survey_no + 1
print reply_sms
Comment