Sep-15-2021, 05:06 PM
hello,
thanks to both of you
would you care to explain the code?
thanks to both of you
would you care to explain the code?
if line.startswith("#EXTINF"): #this makes the loop target a certain line out_text += line #i see this increments a variable previously set to "" name = line.split(",", 1)[1] #i gather this splits line into some sort of array but i fail to grasp its use. #could you point me to somewhere this method is explained? out_text += f'\n{name}.mp3\n' #at a loss. what's f? else: out_text += f"{line}\n"just for the sake of precision, i think it could be good practice to close a file, i guess that print is just to check the whole thing and can be left along, it gives:
in_text = open("playlist.m3u", "r").read() out_text = "" for line in in_text.splitlines(): if line.startswith("#EXTINF"): out_text += line name = line.split(",", 1)[1] out_text += f'\n{name}.mp3\n' else: out_text += f"{line}\n" with open("new_playlist.m3u", "w") as f: f.write(out_text) f.close()is it no so?