我对递归函数的返回有一个奇怪的问题。它总是返回“无”而不是 temp_blocks。他将在其他情况下编写 temp_blocks (块列表,而不是无),但如果我调用该函数,它似乎不会返回列表blocks = _searchblocks(roots, left_edge, right_edge)
。这是一个普遍的问题,还是我的错?
def _searchblocks(blocks, left_edge, right_edge):
temp_blocks = []
for block in blocks:
if np.any(block.left_edge >= left_edge) \
and np.any(block.right_edge <= right_edge):
temp_blocks.append(block)
if len(temp_blocks) == 1:
_searchblocks(temp_blocks[0].children, left_edge, right_edge)
else:
print(temp_blocks)
return temp_blocks