0

My base class and internal subclass in 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

and in an adjacent file testc2subclass.py

from c2base import C2Methods

    class TestC2Subclass(C2Methods):

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

In trying to use it I wrote the following

 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, {}, {})

The console only shows the internal subclass... executeScript = TestC2Subclass ++++++++++++++ executeScript ++++++++++++++ XXXXXXXXXXXXXXXXXXXXXXX c2base subclasses [<class 'correlator.api.methods.c2base.InternalSubclass'>]

I have other base classes and subclasses that are working fine. I do not see why this only shows the InternalSubclass.

Mike Oliver
  • 163
  • 1
  • 3
  • 14
  • Please give a [mre]; do you ever actually import the file containing the second subclass? Also note https://stackoverflow.com/q/1680528/3001761 – jonrsharpe Jan 22 '23 at 07:42

1 Answers1

1

Yes, John identified the problem was the classes had not been imported.

Mike Oliver
  • 163
  • 1
  • 3
  • 14