python-3.x 我有一个基类和一个内部子类,外部子类在另一个相邻文件中,只有内部子类显示在__subclasses()中

piztneat  于 2023-01-27  发布在  Python
关注(0)|答案(1)|浏览(121)

www.example.com中的基类和内部子类c2base.py

class C2Methods(object):
    _instruction = {}
    _request = {}
    _paramter = {}
    _data = {}
    _responsedata = {}

def init(self, instruction, request, parameter, data):
    _instruction = instruction
    _request = request
    _paramter = parameter
    _data = _data

def execute(self, instruction, request, parameter, data):
    print('execute')
    _responsedata = {}
    return (_responsedata)

class InternalSubclass(C2Methods):
    pass

并在相邻的文件www.example.com中testc2subclass.py

from c2base import C2Methods

    class TestC2Subclass(C2Methods):

        def execute(self, instruction, request, parameter, data):
            print('TestC2Subclass.execute()')
            _responsedata = {}
            return (_responsedata)

在尝试使用它时,我写了以下内容

c2subclasses = c2base.C2Methods.__subclasses__()
            print('XXXXXXXXXXXXXXXXXXXXXXX c2base subclasses', c2subclasses)
            for cls in c2subclasses:
                if executeScript == cls.__name__:
                    responsedata = {}
                    responsedata = cls.execute(cls, instruction_row, request, {}, {})

控制台仅显示内部子类... executeScript = TestC2Subclass ++++++++++++++ executeScript ++++++++++++++ XXXXXXXXXXXXXXXXXXXXXXX c2base subclasses [<class 'correlator.api.methods.c2base.InternalSubclass'>]
我有其他工作正常的基类和子类。我不明白为什么这只显示InternalSubclass。

euoag5mw

euoag5mw1#

是的,John发现问题是这些类尚未导入。

相关问题