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,
uj5u.com熱心網友回復:
將單詞保存到串列中,然后將它們加入空格:
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://www.uj5u.com/qiye/486479.html
下一篇:裁剪大資料檔案
