为什么我会犯这个错误?有人能帮我解决这个问题吗?我试着在Progress.display()中调用class project中的display函数,或者任何人都有关于如何显示用户输入的其他解决方案?

我怎样才能同时在课堂和进度课上输入阶段?谢谢你的帮助

超级().display()

这是密码

class Project:
    def __init__(self, name="", job="", **kwargs):
        super().__init__(**kwargs)
        self.name = name
        self.job = job

    def display():
        print("name: ", (self.name))
        print("job: ", (self.job))

    @staticmethod
    def prompt_init():
        return dict(name=input("name: "), job=input("job: "))


class Stages(Project):
    def __init__(self, stages="", **kwargs):
        super().__init__(**kwargs)
        self.stages = stages

    def display(self):
        super().display()
        print("stages: ", (self.stages))

    @staticmethod
    def prompt_init():
        parent_init = Project.prompt_init()

        choice = None
        while choice not in (1, 2, 3, 4, 5, 6):

            print("Insert your stage now: ")
            print("1. Planning")
            print("2. Analysis")
            print("3. Design")
            print("4. Implementation")
            print("5. Testing")
            print("6. Release")

            choice = input("enter your choice: ")
            choice = int(choice)

            if choice == 1:
                stages = "Planning"
            elif choice == 2:
                stages = "Analysis"
            elif choice == 3:
                stages = "Design"
            elif choice == 4:
                stages = "Implementation"
            elif choice == 5:
                stages = "Testing"
            elif choice == 6:
                stages = "Release"
            else:
                print("no such input, please try again")

            print(name)
            print(stages)


class Progress(Project):
    def __init__(self, progress="", **kwargs):
        super().__init__(**kwargs)
        self.progress = progress

    def display(self):
        super().display()
        print("progress: ", (self.progress))

    @staticmethod
    def prompt_init():
        parent_init = Project.prompt_init()

        choice = None
        while choice not in (1, 2, 3, 4):

            print("1. 25%")
            print("2. 50%")
            print("3. 75%")
            print("4. 100%")

            choice = input("enter your choice[1-4]: ")
            choice = int(choice)

            if choice == 1:
                progress = "25%"
            elif choice == 2:
                progress = "50%"
            elif choice == 3:
                progress = "75%"
            elif choice == 4:
                progress = "100%"
            else:
                print("no such input, please try again")

            print(progress)
        parent_init.update({"progress": progress})
        return parent_init


class A(Stages, Progress):
    def prompt_init():
        init = Stages.prompt_init()
        init.update(Progress.prompt_init())
        return init

    prompt_init = staticmethod(prompt_init)


class New:
    type_map = {("stages", "progress"): A}

    def add_project_test(self, name, job, stages):
        init_args = Project.prompt_init()
        self.project_list.append(Project(**init_args))

    def __init__(self):
        self.project_list = []

    def display_project():
        for project in self.project_list:
            project.display()
            print()

    def add_progress(self):
        init_args = Progress.prompt_init()
        self.project_list.append(Progress(**init_args))

    def add_project(self):
        ProjectClass = self.type_map[A]
        init_args = ProjectClass.prompt_init()
        self.property_list.append(ProjectClass(**init_args))


my_list = New()
my_list.add_progress()
my_list.display_project()

推荐答案

每次在方法中使用super()时,都需要在实例方法或类方法中.你的staticmethod人不知道他们的超类是什么.注意:

class Funky:
    def groove(self):
        print("Smooth")

    @staticmethod
    def fail():
        print("Ouch!")

    @classmethod
    def wail(cls):
        print("Whee!")


class Donkey(Funky):
    def groove(self):
        print(super())

    @staticmethod
    def fail():
        try:
            print(super())
        except RuntimeError as e:
            print("Oh no! There was a problem with super!")
            print(e)

    @classmethod
    def wail(cls):
        print(super())


a_donkey = Donkey()
a_donkey.groove()
a_donkey.fail()
a_donkey.wail()

输出:

<super: <class 'Donkey'>, <Donkey object>>
Oh no! There was a problem with super!
super(): no arguments
<super: <class 'Donkey'>, <Donkey object>>

以下是您的代码,经过调试,带有一些额外的功能和测试:

class Project:
    def __init__(self, name="", job="", **kwargs):
        super().__init__(**kwargs)
        self.name = name
        self.job = job

    def display(self):
        print("name: ", self.name)
        print("job: ", self.job)

    @staticmethod
    def prompt_init():
        return dict(name=input("name: "), job=input("job: "))


class Progress(Project):
    def __init__(self, progress="", **kwargs):
        super().__init__(**kwargs)
        self.progress = progress

    def display(self):
        super().display()
        print("progress: ", self.progress)

    @staticmethod
    def prompt_init():
        parent_init = Project.prompt_init()
        progress = input("your progress: ")
        parent_init.update({
            "progress": progress
        })
        return parent_init


class New:
    def __init__(self):
        self.project_list = []

    def display_project(self):
        for project in self.project_list:
            project.display()
            print()

    def add_project(self):
        init_args = Project.prompt_init()
        self.project_list.append(Project(**init_args))

    def add_progress(self):
        init_args = Progress.prompt_init()
        self.project_list.append(Progress(**init_args))


my_list = New()
my_list.add_project()
my_list.add_progress()
my_list.display_project()

Python-3.x相关问答推荐

如何在Python Matplotlib中在x轴上放置点

这是重命名极地df列的最好方式吗?

如何通过Pandas为不同的列集垂直设置列数据?

pandas查找另一列中是否存在ID

谁能解释一下这个带邮编的多功能环路?

给定panda代码的分组和百分比分布pyspark等价

添加任意数量的 pandas 数据框

来自嵌套字典的完整地址

包含值超出范围的 ID 的新 DataFrame 列?

获取以特定字母开头的姓氏

如何在 VSCode 的在 Cloud Run Emulator 上运行/调试构建设置中添加 SQL 连接

类型提示和链式赋值以及多重赋值

Python 3 变量名中接受哪些 Unicode 符号?

ValueError:预期的 2D 数组,得到 1D 数组:

如何在 Selenium 和 Python 中使用类型查找元素

谁能给我一个 Python 3 中标准输入和标准输出的快速教程?

如何在 Python 3.2 中退出?

在 Ipython 中使用 Pylint (Jupyter-Notebook)

如何将发音相似的词放在一起

如何更改 tkinter 文本小部件中某些单词的 colored颜色 ?