首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AttributeError:“超级”对象没有属性“compare_files”

AttributeError:“超级”对象没有属性“compare_files”
EN

Stack Overflow用户
提问于 2018-07-15 04:00:22
回答 1查看 3.9K关注 0票数 0

带有继承的示例代码,按预期工作。

代码语言:javascript
复制
class Animal:
    def action(self, value_1, p=None):
        print ('Parent action %d %d' % (value_1, p))
        return value_1 + 1 + p

class Dog(Animal):
    def action(self, value):
        print ('Dog action in child')
        return super(Dog, self).action(value, 1)

print(Dog().action(10))

下面是另一个继承示例,其中引发以下错误。

AttributeError:“超级”对象没有属性“compare_files”

代码语言:javascript
复制
class FileCompare:
    def compare_files(self, actual_filename, ref_filename, field_to_skip=None):
        return True

class MetaFileCompare(FileCompare):
    def compare_files(self, actual_file, ref_file):
        return super(FileCompare, self).compare_files(actual_file, ref_file,
                    0)

class WorkerFileCompare(FileCompare):
    def compare_files(self, actual_file, ref_file):
        return super(FileCompare, self).compare_files(actual_file, ref_file,
                    5)

print (WorkerFileCompare().compare_files('a', 'b'))

除了类名、方法名和返回类型之外,代码几乎是相同的。听起来好像我漏掉了什么很傻的东西。没有错误。你能提供一些指点吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-07-15 04:44:45

把它从

代码语言:javascript
复制
class MetaFileCompare(FileCompare):
    def compare_files(self, actual_file, ref_file):
        return super(FileCompare, self).compare_files(actual_file, ref_file,
                    0)

代码语言:javascript
复制
class MetaFileCompare(FileCompare):
    def compare_files(self, actual_file, ref_file):
        return super(MetaFileCompare, self).compare_files(actual_file, ref_file,
                    0)

这就是我犯的愚蠢的错误。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51345136

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档