繁体   English   中英

调用父__init __()

[英]Calling Parent __init__()

我使用的是Python 2.6.6。

我已将我的错误代码缩小到这两个类:

class Graph(object):
  def __init__(self, name):
    self.name = name
    self.testme = 3

class StepPlot(Graph):
  def __init__(self, name):
    print("fdasfdsf")
    print(dir(super(Graph, self)))
    super(Graph, self).__init__(name)

不幸的是,当我使用StepPlot('fdsfa')实例化StepPlot时,我得到了错误

TypeError: object.__init__() takes no parameters

它不应该能够采取一个参数?

看着

何时调用Python的super().__ init __()?

这个班级组织应该工作。

我是否从根本上遗漏了一些东西? 任何帮助,将不胜感激。

super的第一个参数应该是调用它的类:

super(StepPlot, self).__init__(name)

有关更多信息,请参阅文档的链接。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM