1
class Config_A(test.Case):
    def insert(self, protocol_id):
        ...
        ...


class Config_B(test.Case):
    ...
    ....
    ....

    def test_somecase(self):
        self.insert(10)

Here def insert() is a common method, which is required by multiple classes. From class Config_B, its not able to access the definition of insert() defined in Config_A. One solution is that, define it in Config_B and make use of. But it's a duplication of code. How can we do this without writing duplicate code?

Krishna
  • 49
  • 6

1 Answers1

1
class Config_A():
    def insert(self, protocol_id):
        print 'protocol_id=',protocol_id

class Config_B(Config_A):
    def test_somecase(self):
        Config_A().insert(10)

def main():
    obj = Config_B()
    obj.test_somecase()

if __name__ == '__main__':
    main()

This one worked.

Krishna
  • 49
  • 6
  • 1
    `Config_A().insert(10)` can be replaced by `self.insert(10)`. Otherwise, you create a temporary instance that is immediately destroyed. – OneCricketeer Sep 17 '18 at 07:24