此功能为什么不将文本文件中的值附加到我的列表中?

问题描述 投票:0回答:1
def read1(file):                #this function will read and extract the first column of values from the
    with open(file,"r") as b:        # text allowing us to access it later in our main function
        list1 = list(b)
        lines = b.readlines()
        result1 = []
        for i in lines:
            result1.append(list1.split()[0])
    b.close
    return result1
x = read1("XRD_example1.txt")

是否清楚可见任何错误?

python python-3.x list append readfile
1个回答
0
投票

您愿意:

© www.soinside.com 2019 - 2024. All rights reserved.