我试图通过从我的当地目录进口我的模块来测试我的模块。 该法典在设立案件时毫无用处,职能要求从同一页(无进口)上发出。 然而,当我把代码块移至模块并进口时,它保留了以下回归错误:
Following code is from my locally stored module named Admin.py:
class User:
def __init__(self, name, last, age, nationality):
self.name = name
self.last = last
self.age = age
self.nationality = nationality
def describe_user(self):
print(f"
Admin name is {self.name.title()}, last name is {self.last.title()}, age is {self.age} and is of {self.nationality.title()} nationality
")
def greet_user(self):
print(f"
Hello! {self.name.title()}, welcome to the XYZ Consultancy Services Ltd.
")
class Privileges:
def __init__(self, privileges):
self.privileges = privileges
def show_privileges(self):
print("Privileges of the admin are:
")
for privilege in self.privileges:
print(f"- {privilege}")
class Admin(User):
def __init__(self, name, last, age, nationality):
super().__init__(name, last, age, nationality)
self.privileges = Privileges(privileges)
privileges = ["can add post", "can delete post", "can ban user"]
在我试图从我的当地模块Admin.py上进口密码,并试图执行该守则的网页上。
from user import Admin
priv = Admin("veronica", "smith", 26, American )
priv.greet_user()
priv.describe_user()
priv.privileges.show_privileges()
Following is the returned output (error):
92 # super().__init__(name, last, age, nationality)
93 # self.privileges = Privileges(privileges)
95 privileges = ["can add post", "can delete post", "can ban user"]
---> 97 priv = Admin("veronica", "smith", 26, American )
99 priv.describe_user()
101 priv.privileges.show_privileges()
25 def __init__(self, name, last, age, nationality):
26 super().__init__(name, last, age, nationality)
---> 27 self.privileges = Privileges()
TypeError: Privileges.__init__() missing 1 required positional argument: privileges
When this entire code is run from the same page, I get the following which is expected by me:
Hello! Veronica, welcome to the XYZ Consultancy Services Ltd.
Admin name is Veronica, last name is Smith, age is 26 and is of American nationality
Privileges of the admin are:
- can add post
- can delete post
- can ban user
我尝试了几乎每一种可能的调和/组合,以纠正这种立场上的错误,但即使在工作6小时之后,我也未能解决这一错误。