我需要一个带有split或re.findall的python代码来从文件中读取以#EXTINF开头的行:然后删除完整的行,只保留最后一个单词或句子…例如:
#EXTINF:-1 tvg-id="" tvg-name="|AR| beIN MOVIES 1 HD" tvg-logo="" group-title="OSN & BEIN-entre",|AR| beIN MOVIES 1 HD
#EXTINF:0,GLORY 77 BOX
#EXTINF:0 group-title="Tunisia"tvg-logo="http://logo.ddnb.tn/logochanel/1.png",National 1
#EXTINF:-1,Mera Farz | Superhit Hindi Action Movie | Amrishpuri ,Sri Devi , Nagarjuna
#EXTINF:1, FOOTBALL
#EXTINF:0,Aaryaa News
试试这个:
with open("sample.txt") as f:
print("n".join(l.rsplit(",")[-1].strip() for l in f.readlines()))
输出:
|AR| beIN MOVIES 1 HD
GLORY 77 BOX
National 1
Nagarjuna
FOOTBALL
Aaryaa News