I am doing a dynamic generation of classes that can be statically defined at compilation time. A simple case that I have now looks something like this:
class Base(object):
def __init__(self, **kwargs):
self.do_something()
def ClassFactory(*args):
some_pre_processing()
class GenericChild(Base):
def __init__(self, **kwargs):
self.some_processing()
super(GenericChild, self).__init__(*args, **kwargs)
return GenericChild
Child1 = ClassFactory(1, 'Child_setting_value1')
Child2 = ClassFactory(2, 'Child_setting_value2')
Child3 = ClassFactory(3, 'Child_setting_value3')
Upon import, the Python interpreter seems to be compiled into bytecode, then executes the file (thus generating Child1, Child2and Child3) once per Python instance.
Is there a way to tell Python to compile the file, execute it once to unzip the classes Child, and then compile it to a file pycso that unpacking is done only once (even through sequential execution of the Python script)?
, , factory Child . , , (, C- C).