基本上,这就是我目前拥有的:
在 script1 我有这个:
class Student(object):
def __init__(self,name,school):
self.name = name
self.school = school
在 script2 我有这个:
class Teacher(object):
def __init__(self,name,school):
self.name = name
self.school = school
在 script3 中,我定义了实例并检查学校是否匹配:
student1=Student("Alex","Highschool")
teacher1=Teacher("Mary","Highschool")
if student1.school == teacher1.school:
print("yes")
但是,我想合并检查学校是否在 script1 或 script2 中匹配。这是我尝试过的:
class Teacher(object):
def __init__(self,name,school):
self.name = name
self.school = school
def _check_if_school_matches(self,Student()):
if self.school == Student.school:
print("yes")
但是当然我得到了一个SyntaxError,我不能说,_check_if_school_matches(self,student1)因为student1还没有定义。
相关分类