Python 简单继承问题

Python 简单继承问题,python,inheritance,scrapy,Python,Inheritance,Scrapy,我在继承方面有问题。可能是初学者的错误。我做了两个脏蜘蛛: from scrapy.spiders import SitemapSpider class SchemaorgSpider(SitemapSpider): name = 'schemaorg' def parse(self, response): print "parse" ... 及 我基本上是在mparse中定义所有逻辑,然后在所有子类中使用它。当我运行第二个spider时,我

我在继承方面有问题。可能是初学者的错误。我做了两个脏蜘蛛:

from scrapy.spiders import SitemapSpider

class SchemaorgSpider(SitemapSpider):
    name = 'schemaorg'

    def parse(self, response):
        print "parse"
        ...

我基本上是在mparse中定义所有逻辑,然后在所有子类中使用它。当我运行第二个spider时,我只看到“parsefromrule”,而没有看到“parse”。在我看来,这就像“继承101”,但它不起作用。 怎么了? 编辑:无刮痕测试,有效:

class a(object):
    def aa(self):
        print "hello"

class b(a):
    def bb(self):
        self.aa()
class c(b):
    def cc(self):
        self.aa()

hello = c()
hello.cc()
hello.bb()
hello.aa()
我看到所有3个“你好”。我不明白为什么它对Scrapy不起作用


Edit2:如果我把self.blabla(response)而不是self.parse(response)放进去,我会得到一个错误。这意味着它正在寻找一个现有的方法。

您的代码片段(当去掉零碎的东西时)不会重现问题。请发布一个mcve@brunodesshuilliers不幸的是,我无法用mcve的例子重现它。我尝试了一个simpole a级…B(a)级的例子,效果很好。我希望这是一个简单的关于可见性的继承问题。你的代码片段(当去掉零碎的东西时)不会重现这个问题。请发布一个mcve@brunodesshuilliers不幸的是,我无法用mcve的例子重现它。我尝试了一个simpole a级…B(a)级的例子,效果很好。我希望这是一个关于可见性的简单继承问题。
class a(object):
    def aa(self):
        print "hello"

class b(a):
    def bb(self):
        self.aa()
class c(b):
    def cc(self):
        self.aa()

hello = c()
hello.cc()
hello.bb()
hello.aa()