# How to transmit a parameter to a function called in an other function?

Here are 2 functions: the second one calls the first one but obviously it doesn't transmit the value of sw to the first and I have an error of execution. So how should I do to obtain that sw be transmitted to pos_rat(x, y, sw) by ratio_for_pivot(x, y, sw)?

 def pos_rat(x, y, sw):
if y > 0:
return x/y
else:
if sw == 1:
return "-"
elif sw == 2:
return -100000

def ratio_for_pivot(mat, var_ent, sw):
return [pos_rat(mat[i][mat.ncols() - 1], mat[i][var_ent], sw)
for i in range(mat.nrows() - 1)]

edit retag close merge delete

Ideally, provide a minimal example of calling the functions to illustrate the question.

Sort by » oldest newest most voted

I know this is more a Python question. Here is my answer:

def pos_rat(x, y, sw):
if y > 0:
return x/y
else:
if sw == 1:
return "-"
elif sw == 2:
return -100000

def ratio_for_pivot(mat, var_ent, sw):
a = [pos_rat(mat[i][mat.ncols() - 1], mat[i][var_ent], sw)
for i in range(mat.nrows() - 1)]
return a

more