This question may sound silly, but this is what I'm going through, I wrote a project with some modules, and certan levels of functions, as one function calls the another one and so on, the final function to return the result, a dictionary.
when I call the function on the first level, everything works well to the last funciton,
while at the last function,
printing the return dictionary works well while returning the dictionary with return result
return None
I have a finite number of functions, spread over different modules.
# on module 1
def funciton_one(the_user_input):
# code to process param at
# stage 1 if conditions are met
function_two(parameter,the_user_input)
# on module 2
def function_two(parameter,the_user_input):
# code to process param at
# stage 2 if conditions are met
function_three(parameter,the_user_input)
# on module 3
def function_three(parameter,the_user_input):
# code to process param at
# stage 3 if conditions are met
function_four(parameter,the_user_input)
# on module 4
def function_four(parameter,the_user_input):
# code to process param at
# stage 4 if conditions are met
function_five(parameter,the_user_input)
# on module 5
def function_five(parameter,the_user_input):
# code to process param at
# stage 5 if conditions are met
function_six(parameter,the_user_input)
# on module 1
def function_six(parameter,the_user_input):
# code to the process parameter and original parameter
# stage 6 if conditions are met
return result
user_input = 'blahblah'
processed = function_one(user_input)
what I'm doing wrong here?
Edit: Its like input is passed through all the functions, (the input to the first function is the original_parameter) and the parameter is processed values at different levels.
Update: Much mess up, renaming the variables. Thanks.
I take it you want to get your final output into processed
? You need to return the final result to each of the functions, so function_six
returns to function_five
, returns to function_four
, etc., until function_one
returns into the processed
variable.
I changed your code slightly to make it work (there was no original_param
in function_one
. Next time, please make sure your example code is valid before posting it.
# on module 1
def function_one(parameter):
return function_two(parameter,parameter)
# on module 2
def function_two(parameter,original_param):
return function_three(parameter,original_param)
# on module 3
def function_three(parameter,original_param):
return function_four(parameter,original_param)
# on module 4
def function_four(parameter,original_param):
return function_five(parameter,original_param)
# on module 5
def function_five(parameter,original_param):
return function_six(parameter,original_param)
# on module 1
def function_six(parameter,original_param):
result = "foobar"
return result # returns foobar
user_input = 'blahblah'
processed = function_one(user_input)
print processed # prints foobar