How to structure a multi-steps(and substeps) scripts

超 李 lee_chau at live.cn
Sun Apr 10 01:08:16 EDT 2011


Hi everybody. I wrote a script and it's code structure like this:
def step1:    local_var1 = ...    # some other variable definitions for step1    def substep11:        pass    def substep12:        pass    # more substeps
def step2:    local_var1 = ...    # some other variable definitions for step2    def substep21:        pass    def substep22:        pass    # more substeps    # more steps ...
def stepN:    #vars and substeps...    global_var1 = ...# more global var definitions...if step1.return_success:    step2    step3    ...    stepN    As you see, this script consists of serveral steps(a list of commands), and a step often consists of several substeps. I used to put all the steps in one module, where one step corresponding to one funciton and one substep corresponding to one nested function. It's now a headache to maintain this script because of totally 1000+ lines of code. Meanwhile when I manipulate different projects with this script I need to modify the value of some variables and detailed task logic. Obviously it's a dirty work to modify the source code directly for different projects. So I wonder if I should put different steps in different modules to shorten the length of each module? If I should put the default value of a variable and high level task logic in a abstract class, and define specific value and detailed task logic in concrete subclass? Is there any design patterns available for this kind of multi-steps scripts?
Thanks! 		 	   		  


More information about the Python-list mailing list