错误原因:
请检查你的__init__
函数名或者其定义有没有写错。
注意:下划线左右是两个;中间的英文字母是四位
import unittest
class Student(object):
def __int__(self, name, score):
self.name = name
self.score = score
def get_grage(self):
if self.score > 100 or self.score < 0:
raise ValueError('%s is a unvalid score' % self.score)
if self.score >= 60 and self.score <80:
return "B"
if self.score >= 80 and self.score <=100:
return "A"
return "C"
报错如下:
ERROR: test_0_to_60 (_ main _.TestStudent)
Traceback (most recent call last):
File "D:/py_scripts/blank.py", line 37, in test_0_to_60
s1 = Student("Bart", 0)
TypeError: object() takes no parameters
初始化函数,我把__init__
写成了__int__
...
改成正确的函数名以后,就可以成功调用,不会报错了
网友评论