繁体   English   中英

如何读取一块模式文件?

[英]How to read a block of pattern file?

我有一些模式文件,我喜欢阅读其中的一小部分。

示例:text.txt

Recipe: 
'name' 
Ingredients:
Item 1
Item 2
Item N... 
How to prepare:
Item 1
Item 2
Item N... 

我只想得到原料。

handle = open("test.txt", "r")
lines = handle.readlines()
lines = [line.strip() for line in lines]
st_idx = lines.index("Ingredients:")
ed_idx = lines.index("How to prepare:")
Ingredients = lines[st_idx:ed_idx]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM