Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23131

how to divide large python file into small files without change program structure [closed]

$
0
0

I face a program like following:

# This code just used to reflect the recursive structure, DO NOT take it grammatically !!class A:    def __init__(self) -> None:        pass    def check(self, element):        if element == 'TypeA':            self.__validate_TypeA(element)        if element == 'TypeB':            self.__validate_TypeB(element)        if element == 'TypeC':            self.__validate_TypeC(element)    def __validate_TypeA(self, element):        # implementation..        if element.contains('TypeB'):            self.check('TypeB')        # implementation...    def __validate_TypeB(self, element):        if element.contains('TypeC'):            self.check('TypeC')    def __validate_TypeC(self, element):        if element.contains('TypeA'):            self.check('TypeA')    # thousands of codes here...

In this class, methods are depend on each other; In my project, there are half hundreds of Types like 'TypeA', 'TypeB', and they are coorelated and might call check method in their own implementaion; now my class grows to 4 thousands of lines of code, the maintaining is becoming tricky.

I have tried using inheritence, it does not work out;I have tried using exec(), built-in, but it will forcefully break the code into multi files, losing the possiblity of using IDE for code highlighting, etc...

So is there a way to do following? :

  1. divide my class into multi files,might be one file for one Type implementation
  2. do not influence the program strcuture

In C/C++, this could be easiliy accomplished using #include, i do not know how to do it in Python.


Viewing all articles
Browse latest Browse all 23131

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>