Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 无参数实例化_Python_Python 3.x_Instance - Fatal编程技术网

Python 无参数实例化

Python 无参数实例化,python,python-3.x,instance,Python,Python 3.x,Instance,因此,我试图使用另一个类中的方法,但我必须添加该类中的所有参数,我使用的是来自的方法。这有什么关系吗 class MainPage(tk.Frame): def __init__(self, parent, controller): tk.Frame.__init__(self, parent) label = tk.Label(self, text = "aaaa") label.pack(pady = 10, padx = 10)

因此,我试图使用另一个类中的方法,但我必须添加该类中的所有参数,我使用的是来自的方法。这有什么关系吗

class MainPage(tk.Frame):

    def __init__(self, parent, controller):
       tk.Frame.__init__(self, parent)
       label = tk.Label(self, text = "aaaa")
       label.pack(pady = 10, padx = 10)

       A = managers()
       method = getattr(A, printAll) ## "printAll" is the method im trying to get 

       addemployee = tk.Button(self, text = "Start", command = method)
       addemployee.pack(pady = 10, padx = 10)



class managers(workers):

    def __init__(self, firstname, surname, age, postcode, wage, Employees = None):
        super().__init__(firstname, surname, age, postcode, wage)

    def printAll(self): #### the method i want to use
        for emp in self.employees:
            print(emp.Fullname(), "-", emp.Age(), "-", self.Postcode(), "-", self.Wage())

您可以使用默认值,这样就不必传递所有内容

class managers(workers):

def __init__(self, firstname="fname", surname="sname", age="196", postcode="pc", wage="1$", Employees = None):

另一个允许您完全自由的选项,如中所建议的,是使用args和关键字args
def\uu init\uuu(self,*args,**kwargs)传递参数:

如果不实例化这些属性,您将如何使用该方法,你的MainPage类与这个问题有什么关系?@coldspeed我不想重新添加参数,因为我已经在类的底部创建了一个包含所有信息的对象
a=managers(“Sha”、“Jan”、21、“UB4 NM3”、1900000)
,至于主页,这只是一个示例,我没有提供所有代码。只有必要的部分。