[Tutor] class method problem

Roelof Wobben rwobben at hotmail.com
Sat Sep 25 20:51:10 CEST 2010



Hello,

Still the same errors

Roelof


> ----------------------------------------
>> Date: Sat, 25 Sep 2010 19:33:52 +0100
>> Subject: Re: [Tutor] class method problem
>> From: andrefsp at gmail.com
>> To: rwobben at hotmail.com
>>
>> Your method receives 4 arguments and you didn't define one default.
>> Try to do something like this:
>>
>> def find(self, strng=None, ch=None, start=None, stop=None):
>>
>> Or any other default values that matches your needs.
>>
>>
>>
>> On 25 September 2010 19:15, Roelof Wobben wrote:
>>>
>>>
>>> Hello,
>>>
>>> I have this code:
>>>
>>> class zoeken() :
>>> á ápass
>>> á ádef __len__(self):
>>> á á á áreturn 0
>>> á ádef __str__(self):
>>> á á á áreturn test2
>>> á ádef find(self, strng, ch, start, stop):
>>> á á á áindex = start
>>> á á á áwhile index < len(strng) and index < stop:
>>> á á á á á áif strng[index] == ch:
>>> á á á á á á á áreturn index
>>> á á á á á áindex += 1
>>> á á á á á áreturn -1
>>>
>>>
>>> test = zoeken()
>>> test.woord = "tamara"
>>> test2 = zoeken.find(test, "a", 1,5)
>>> print test(test2)
>>>
>>> But now I get this message :
>>>
>>> Traceback (most recent call last):
>>> áFile "C:\Users\wobben\workspace\oefeningen\src\test.py", line 20, in
>>> á átest2 = zoeken.find(test, "a", 1,5)
>>> TypeError: find() takes exactly 5 arguments (4 given)
>>>
>>> I can do zoeken.find (test2,test, "a", 1,5) but then I get this message:
>>>
>>> Traceback (most recent call last):
>>> áFile "C:\Users\wobben\workspace\oefeningen\src\test.py", line 20, in
>>> á ázoeken.find( test2, test, "a", 1,5)
>>> NameError: name 'test2' is not defined
>>>
>>>
>>> Roelof
>>>
>>> _______________________________________________
>>> Tutor maillist á- áTutor at python.org
>>> To unsubscribe or change subscription options:
>>> http://mail.python.org/mailman/listinfo/tutor
>>>
>>
>>
>>
>> --
>> Andreh Palma 		 	   		  


More information about the Tutor mailing list