Program structure during long data processing python script

For my current job, I write several lengthy (think from hours to days) scripts that process intensive CPU data. The program flow is very simple - it goes into the main loop, completes the main loop, saves the output signal and ends: The main structure of my programs tends to look like this:

<import statements>
<constant declarations>

<misc function declarations>

def main():
   for blah in blahs():
      <lots of local variables>
      <lots of tightly coupled computation>

      for something in somethings():
          <lots more local variables>
          <lots more computation>

   <etc., etc.>

   <save results>

if __name__ == "__main__":
    main()

It quickly becomes unmanageable, so I want to reorganize it into something more manageable. I want to make it more convenient without sacrificing speed.

, , - . python ? , , , .

? python, , - .

+3
3

, /, / , , .

, ( ) . , , , . , ... . , , C, , .

, <lots of tightly coupled computation> <lots more computation>. , for .

+2

( ) . (, ) , unit test .

IMO, , .

+1

, ...

, , , , .

, " ", " " - , "" . , Google.

+1

Source: https://habr.com/ru/post/1747368/


All Articles