<p>下面的文本文件显示频道名称的说明&;频道事件</p>
<p><strong><em>desc.txt文件:</em><strong></p>
<pre><code>Channel Name: CBS
Event Name: FIFA World Cup 2018 Qualifying
Channel Name: BEINSPORTS
Event Name: NFL
</code></pre>
<p>下面的Python代码只查找第一个“事件名称”和相关描述</p>
<pre><code>flist = open('/tmp/desc.txt').readlines()
for line in flist:
if line.startswith("Event Name:"):
eventname = line[12:-1]
file2 = open('/tmp/test_live.txt','w')
file2.write(eventname + "\n")
</code></pre>
<p>我想要的是下面的描述,我现在得到的是
文件中有“2018年国际足联世界杯预选赛”</p>
<p><strong><em>测试_live.txt</em></strong></p>
<pre><code>FIFA World Cup 2018 Qualifying
NFL
</code></pre>