python for x in y loop does not complete -


trying make script extracts song information playlist.

this beginning of playlist:

#extm3u #extinf:402,junior's eyes - black sabbath /users/omitted/black sabbath/[1978] never die!/03. junior's eyes.mp3 #extinf:327,after forever - black sabbath /users/omitted/black sabbath/[1971] master of reality/02. after forever.mp3 #extinf:341,killing live - black sabbath /users/omitted/black sabbath/[1973] sabbath bloody sabbath/05. killing live.mp3 #extinf:210,rock 'n' roll doctor - black sabbath /users/omitted/black sabbath/[1976] technical ecstasy/06. rock 'n' roll doctor.mp3 

and script wrote:

import re  f = open('sabbath.m3u', 'r') ptitle = re.compile('(?<=,)[a-za-z0-9][a-za-z0-9 \']+[a-za-z0-9]') partist = re.compile('(?<=- )[a-za-z0-9][a-za-z0-9 ]+[a-za-z0-9]')  str in f:   title = ptitle.search(str)   artist = partist.search(str)   print artist.group() + ' - ' + title.group()  f.close() 

the result of running script is:

black sabbath - junior's eyes

and that's it. why doesn't loop through entire file? gets line #2 since line #1 '#extm3u' in every .m3u file.

keep in mind, please, want know why doesn't work, not replacement code that'll trick.

there lines in file regex fails match. in case, match object none, , none doesn't have .group() property, causing attributeerror raised. should seeing error in console.

you like

for line in f:   t = ptitle.search(line)   title = t.group() if t else "(n.a.)"    = partist.search(line)    artist = a.group() if else "(n.a.)"    print '{} - {}'.format(artist, title) 

Comments

Popular posts from this blog

gridview - Yii2 DataPorivider $totalSum for a column -

java - Suppress Jboss version details from HTTP error response -

Sass watch command compiles .scss files before full sftp upload -