def recursion(level, param1,param2, ...): #recursion terminator if level >MAX_LEVEL: print_result return #process logic in current level process_data(level, data...) #drill down self.recursion(level+1,p1, ...) #reverse the current level status if needed rverse_state(level)