我有一个大文本文件,我需要从中提取几个值.文本文件有很多我不需要的信息.有没有办法我可以搜索一行中的特定术语并返回该行中的第一个值.请举例如下
text
text text
text
text text text
text text
aaaaa text sum
text
text
text
Run Code Online (Sandbox Code Playgroud)
我需要搜索sum并返回值 aaaaa
有没有办法可以做到这一点?
with open(file_path) as infile:
for line in infile:
if 'sum' in line:
print line.split()[0] # Assuming space separated
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
334 次 |
| 最近记录: |