我正在使用visualstudio。 我有两个Python代码文件,一个是我导入的模块,另一个是我的主类。 我正在学习Python,有些东西我还没有完全理解。你知道吗
有没有人能尽可能详细地向我解释一下我不明白的是什么?你知道吗
我得到一个错误: TypeError:必须是str,而不是讲师
我以为从Employee扩展的讲师类会继承get\u name方法? 我使用super()函数将对象传递给构造函数。你知道吗
from examplepackage.employee_lecturer import Employee
from examplepackage.employee_lecturer import Lecturer
employee_one = Employee("John")
print(employee_one.get_name())
lecturer_one = Lecturer("Emily", "Information Technology")
lecturer_one.print_information()
class Employee:
def __init__(self, n):
self.name = n
def get_name(self):
return self.name
def set_name(self, n):
self.name = n
class Lecturer(Employee):
def __init__(self, n, d):
super().__init__(self)
self.division = d
def set_division(self, div):
self.division = div
def get_division(self):
return self.division
def print_information(self):
print("Name:"+self.get_name())
把
Lecturer
的init
中的super
改成这样您传递的是
self
,而不是参数n
,这就是错误显示为TypeError: must be str, not Lecturer
的原因。必须是n
的str,而不是Lecturer
的self
相关问题 更多 >
编程相关推荐