TextFile.txt 文件包含:
1 one
2 two
3 three
4 four
5 five
蟒蛇程序:
file = open ("x.txt", "r")
for item in file:
x = item.split ('\s')
import numpy as np
a = np.array (x)
print (a)
结果:
['5 five']
但是,想要将 TextFile.txt 的所有元素作为一个数组。如何达到同样的效果?