-
慕姐8265434
试试这个:aList = []with open('file.txt') as handle: for text in handle: aList.append(text.strip().split())print(list(filter(None, aList)))输出是: [['17', '2', '3', '0'], ['5', '16', '11', '7'], ['9', '8', '0', '6'], ['0', '14', '17', '1']]
-
莫回无
更短:with open(filname,'r') as f: print([line.split() for line in f if line.split()])
-
慕码人8056858
希望这有帮助: flread=open('path/to/file/filename','r') for i in flread.readlines(): for k in i.split(' '): a.append(int(k)) a=[] b.append(a) print(b)输出: [[17, 2, 3, 0], [5, 16, 11, 7], [9, 8, 0, 6], [0, 14, 17, 1]]