You should append the item that is a float(stored in the variable Item) and not the string version(stored in the variable line) inside the loop so each item is added as the loop iterates through the items.I also use the split()
function to add every three numbers into another nested list
Here is the fixed code:
table = []
readFile = open(filename)
lines = readFile.readlines()
for i in lines:
for line in i.split():
items = float(lines)
table = [[items]]
print(table)
OR:
readFile = open(filename)
lines = readFile.readlines()
table=[([items] for line in i.split) for i in lines]
print(table)
Output:
[[2.0,7.0,6.0],[9.0,5.0,1.0],[4.0,3.0,8.0]]
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…