我错过了一些关于递归如何在 Python 中工作的信息。我已经采用以下方法来标记一个句子:
def extractIngredientInfo(ingredientLine, sectionTitle):
print 'extractIngredientInfo' + ingredientLine
# set-up some default values for variables that will contains the extracted datas
usmeas = 'N.A'
othermeas = 'N.A'
p_ingredientalt = re.compile('\(or\s(.*?)\)')
malt = p_ingredientalt.search(ingredientLine)
if malt:
ingredientAlt = malt.group(1)
ingredientLine = ingredientLine.replace(malt.group(0), '').strip()
print 'NEW LINE TO TREAT(ALT)' + ingredientLine
extractIngredientInfo(ingredientLine, sectionTitle)
usmeas,othermeas = extractOneIngredientInfo(ingredientAlt)
print 'MALT'
ingredient
yield usmeas, othermeas
#return;
p_ingredientpurpose = re.compile('\(for\s(.*?)\)')
mpurpose = p_ingredientpurpose.search(ingredientLine)
if mpurpose:
ingredientPurpose = mpurpose.group(1)
ingredientLine = ingredientLine.replace(mpurpose.group(0), '').strip()
print 'NEW LINE TO TREAT(FOR)' + ingredientLine
extractIngredientInfo(ingredientLine, sectionTitle)
usmeas,othermeas = extractOneIngredientInfo(ingredientPurpose)
print 'MPURPOSE'
yield usmeas,othermeas
#return;
usmeas,othermeas = extractOneIngredientInfo(ingredientLine)
print 'FINAL'
yield usmeas, othermeas
当我调用这个函数时,我有一个匹配项,malt
它应该导致立即调用递归函数extractIngredientInfo
,但这从来没有发生过(我没有看到第二次调用print 'extractIngredientInfo' + ingredientLine
。有什么具体原因没有发生?