📜  从文本文件读取时更改格式 - 无论代码示例

📅  最后修改于: 2022-03-11 15:00:01.957000             🧑  作者: Mango

代码示例1
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}]\n"

>>> 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) []