📌  相关文章
📜  打开由空格分隔的文本文件 python 代码示例

📅  最后修改于: 2022-03-11 14:45:39.427000             🧑  作者: Mango

代码示例1
numbers = []

#Open the file
with open('file.txt') as fp:
    #Iterate through each line
    for line in fp:

        numbers.extend( #Append the list of numbers to the result array
            [int(item) #Convert each number to an integer
             for item in line.split() #Split each line of whitespace
             ])

print(numbers)