Python Forum
append a string to a modified line
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
append a string to a modified line
#4
This is very different from the first post.

in_text = '''#EXTINF:137,Choir - When Johnny Comes Marching Home
#EXTINF:191,Glenn Miller - When Johnny Comes Marching Home
#EXTINF:308,Chad Mitchell Trio - Johnnie
#EXTINF:205,Joan Baez - Johnny, I Hardly Knew Yeh
#EXTINF:213,Clancy Brothers & Tommy Makem - Johnny I Hardly Knew You
'''

for line in in_text.splitlines():
    if line.startswith("#EXTINF"):
        print(line)
        name = line.split(",")[1]
        print(f'{name}.mp3')
Output:
#EXTINF:137,Choir - When Johnny Comes Marching Home Choir - When Johnny Comes Marching Home.mp3 #EXTINF:191,Glenn Miller - When Johnny Comes Marching Home Glenn Miller - When Johnny Comes Marching Home.mp3 #EXTINF:308,Chad Mitchell Trio - Johnnie Chad Mitchell Trio - Johnnie.mp3 #EXTINF:205,Joan Baez - Johnny, I Hardly Knew Yeh Joan Baez - Johnny.mp3 #EXTINF:213,Clancy Brothers & Tommy Makem - Johnny I Hardly Knew You Clancy Brothers & Tommy Makem - Johnny I Hardly Knew You.mp3
Mr_Blue likes this post
Reply


Messages In This Thread
append a string to a modified line - by Mr_Blue - Sep-13-2021, 04:38 PM
RE: append a string to a modified line - by Mr_Blue - Sep-14-2021, 05:15 PM
RE: append a string to a modified line - by Axel_Erfurt - Sep-14-2021, 05:44 PM
RE: append a string to a modified line - by Mr_Blue - Sep-14-2021, 06:10 PM
RE: append a string to a modified line - by Mr_Blue - Sep-15-2021, 05:06 PM
RE: append a string to a modified line - by Mr_Blue - Sep-16-2021, 07:24 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  PDF properties doesn't show created or modified date Pedroski55 4 1,224 Jun-19-2023, 08:09 AM
Last Post: Pedroski55
  File "<string>", line 19, in <module> error is related to what? Frankduc 9 12,841 Mar-09-2023, 07:22 AM
Last Post: LocklearSusan
  Writing string to file results in one character per line RB76SFJPsJJDu3bMnwYM 4 1,520 Sep-27-2022, 01:38 PM
Last Post: buran
  Inserting line feeds and comments into a beautifulsoup string arbiel 1 1,255 Jul-20-2022, 09:05 AM
Last Post: arbiel
  How to capture string from a line to certain line jerald 1 1,964 Jun-30-2021, 05:13 PM
Last Post: Larz60+
  How to create new line '/n' at each delimiter in a string? MikeAW2010 3 2,960 Dec-15-2020, 05:21 PM
Last Post: snippsat
  How to rename a CSV file by adding MODIFIED in the filename? Python_User 25 8,457 Dec-13-2020, 12:35 PM
Last Post: Larz60+
  How to print string multiple times on new line ace19887 7 5,941 Sep-30-2020, 02:53 PM
Last Post: buran
  Add new line after finding last string in a region Nigel11 1 1,961 Aug-08-2020, 10:00 PM
Last Post: Larz60+
  Searching string in file and save next line dani8586 2 2,375 Jul-10-2020, 09:03 AM
Last Post: dani8586

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020