Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

alterning format when reading from a text file

with open("videos.txt") as f:
    lines = [l.strip() for l in f.readlines()]

available_videos = ""
for line in lines:
    title, video, tags = [x.strip() for x in line.split("|")]
    available_videos += f"{title} ({video}) [{tags}]
"

>>> print(available_videos)
Funny Dogs (funny_dogs_video_id) [#dog , #animal]
Amazing Cats (amazing_cats_video_id) [#cat , #animal]
Another Cat Video (another_cat_video_id) [#cat , #animal]
Life at Google (life_at_google_video_id) [#google , #career]
Video about nothing (nothing_video_id) []
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #alterning #format #reading #text #file
ADD COMMENT
Topic
Name
7+7 =