f=open('D:\py.txt')
song=[]
shi=[]
count=1
def xie_ru(song,shi,count):
song_file = open('D:\\song_' + str(count) + '.txt', 'w')
shi_file = open('D:\\shi_' + str(count) + '.txt', 'w')
song_file.writelines(song)
shi_file.writelines(shi)
song_file.close()
shi_file.close()
for line in f:
if line[:6]!='======':
(role,line_spoken)=line.split(':',1)
if role=='song':
song.append(line_spoken)
#print(song)
if role=='shi':
shi.append(line_spoken)
else:
xie_ru(song,shi,count)
song = []
shi = []
count += 1
xie_ru(song,shi,count)
f.close()
shi: asfgershrh
song:greyhrtujte
shi: asfgersh
song:greyhrtuj
#===========================
shi: asfger
song:greyhrt
shi: asfge
song:greyhr
#============================
shi: asfg
song:greyh
shi: asf
song:grey