当我实例化一个Child
类时,如何为Parent
类提供其args?我是否需要首先使用其args实例化Parent
类,然后在我的Child
args中使用该对象?
class Parent(object):
def __init__(self, args):
self.args = args
class Child(Parent):
def __init__(self):
super().__init__()
object = Child()
我在哪里放置父类args?
答案 0 :(得分:1)
您只需将其传递给父母的__init__
电话。
更改Child
以接受父级的参数,然后在__init__
函数中传递它们。
class Child(Parent):
def __init__(self, args):
super().__init__(args)