无法拆分文本文件中的每一行

时间:2018-05-01 03:23:02

标签: python python-3.x

我在文本文件中有分裂线

代码

import numpy as np

# Data and labels
pred_X = []
pred_Y = []
X = []
Y = []
with open('input.txt', 'r') as fp:
    fd = fp.read()
    for line in fd[:40]:
        line = line.split()
        X.append(line)
    for line in fd[-40:]:
        line = line.split()
        pred_X.append(line)

print(X)

文本文件条目

5000    1.032   R   2.54    B   0.270   0.329   0.132   6   3047    1354    2455    R   2.54    L   0.298   0.386   0.231   1   3400

结果:

[['5'], ['0'], ['0'], ['0'], ['1'], ['.'], ['0'], ['3'], ['2']... ['3'],['4'], ['0'], ['0']]

奇怪的是,这有效:

with open('input.txt', 'r') as fp:
    for line in fp:
        line = line.split()
        print(line)
        time.sleep(3)

0 个答案:

没有答案