将选定的返回函数传递给另一个函数

时间:2017-11-18 11:28:43

标签: python numpy

我正在尝试将函数中的值传递给其他函数。

我计算funcA的值,它返回两个值a,b。这些是numpy数组。

完成计算后,我想将唯一的值,例如 a 从funcA传递给funcB ,并在那里进行其他计算。我想忽略" b"来自funA,同时传递" a"。如果可能的话,我很感兴趣?

def funA(self, x, y):
 .......
return a, b


def funcB(self, data):
......**use only a from funA**.....
return c 

1 个答案:

答案 0 :(得分:0)

如果我理解正确,您可以忽略funA返回的第二个值:

def funA(x, y):
  print('Calling %s with %r, %r' % ('funA', x, y))
  return x, y

def funB(a):
  print('Calling %s with %r' % ('funB', a))
  return a

x, _ = funA(1, 2)
funB(x)
# Calling funA with 1, 2
# Calling funB with 1

另一种方法是使用funA返回的元组的第一个元素:

funB(funA(1, 2)[0])
# Calling funA with 1, 2
# Calling funB with 1