with open("my_file.txt", "r") as f:
next(f) # used to skip the first line in the file
for line in f:
words = line.split()
if words:
print(words[0]) 将产出:
a-1,
b-2,
c-3,我希望它从文件中输出/读取以下内容:
a-1, b-2, c-3,发布于 2022-06-03 17:37:18
将单词保存到列表中,然后在空格中加入它们:
with open("my_file.txt", "r") as f:
first_words = []
next(f)
for line in f:
words = line.split()
if words:
first_words.append(words[0])
print(' '.join(first_words))输出:
a-1, b-2, c-3,https://stackoverflow.com/questions/72493120
复制相似问题