超类可以从单独的模块调用子类方法吗?

时间:2012-10-19 18:20:33

标签: python inheritance

如果类在单独的模块中,那么超类可以调用子类方法“execute”吗?我知道如果它们在同一个模块中,它可以工作。

file2.py

import file1
class TestCase(file1.TestBase):

    def execute(self):
        self._pass()

file1.py

class TestBase:

    def _pass(self):
        print "PASS"

testBase = TestBase()
testBase.execute()

1 个答案:

答案 0 :(得分:1)

是的,但你明确地称之为:

from file1 import TestBase

class TestCase(TestBase):   
    def execute(self):
        TestBase.execute(self) # directly
        super(TestCase, self).execute() # or via super() proxy