def get_ingredients_from_file():
recipe_file = open("/Filepath/", "r")
recipe_text = recipe_file.readlines()
recipe_list = []
i = 1
for line in recipe_text:
if line.startswith('- Ingredients'):
while recipe_text[recipe_text.index(line) + i].startswith('* '):
recipe_list.append(recipe_text[recipe_text.index(line) + i])
i += 1
我还是个新手,但这会查找以“-成分”开头的行,然后检查以“*”开头的行是否会添加到您的食谱列表中。然后你可以用这个列表做任何事情。