0

Sample code with inheritance that works as expected.

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))

Following is another example of inheritance where the following error is thrown.

AttributeError: 'super' object has no attribute 'compare_files'

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'))

Code is almost same except for class name, method name and return type. Sounds like am missing something very silly. There are no typo errors. Can you please provide some pointers?

James Z
  • 12,209
  • 10
  • 24
  • 44
madmatrix
  • 205
  • 1
  • 4
  • 12
  • Fixed the silly mistake that I did. Question can be closed – madmatrix Jul 15 '18 at 04:26
  • 1
    You can write an answer describing how you fixed it, then accept the answer yourself so that the question is properly closed. This will preserve it in case someone else has the same problem in the future. – Burhan Khalid Jul 15 '18 at 04:27
  • You can press the delete button under your question to "close" your question. Or return your question to the original condition and write an answer to your question, which might possibly benefit other users. – Taku Jul 15 '18 at 04:28
  • The question in this current state will be manually closed as off-topic -> no repro, since you fixed the error in your code and we can no longer reproduce the error. – Taku Jul 15 '18 at 04:31
  • Added the answer but "You can accept your own answer in 2 days" – madmatrix Jul 15 '18 at 04:46

1 Answers1

3

Changed it from

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

to

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

this is the silly mistake that I did.

madmatrix
  • 205
  • 1
  • 4
  • 12
  • 2
    It looks like you're on Python 3. If so, you don't have to pass any arguments to `super` at all; `super().compare_files(actual_file, ref_file, 0)` would have worked too. – user2357112 Jul 15 '18 at 04:55
  • Sometimes simple code comparison can be much better than full explanation of the problem and the solution. For me, looking at the above for 15 seconds helped solve my problem, compared to looking at this ( https://stackoverflow.com/questions/6075758/python-super-object-has-no-attribute-attribute-name ) for 15 minutes and done nothing for me. – Donald Jul 29 '19 at 12:19