I am viewing the Pluralsight course on Python. At the end of the module we are to write a Python script. The author does not show how to create two of the scripts. I have them coded as the follows:
main.py
from hs_student import *
james = HighSchoolStudent("james")
print(james.get_name_capitalize)
student.py
students = []
class Student:
school_name = "Springfield Elementary"
def __init__(self, name, s_id=332):
self.name = name
self.s_id = s_id
students.append(self)
def get_name_capitalize(self):
return self.name.capitalize()
...
hs_student.py
import student as student
students = []
class HighSchoolStudent(student):
school_name = "Springfield High School"
def get_school_name(self):
return "This is a High School student"
def get_name_capitalize(self):
original_value = super().get_name_capitalize()
return original_value + "-HS"
...
When running the code, I get an error. From my understanding, I am passing too many arguments to the get_name_capitalize
function. How can I fix this?
The error message is:
TypeError: module() takes at most 2 arguments (3 given)
This code:
class HighSchoolStudent(student):
is trying to inherit from the student
module, not the student.Student
class. Change it to:
class HighSchoolStudent(student.Student):
to inherit from the intended class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With