0
点赞
收藏
分享

微信扫一扫

文件中数据转列表

萍儿的小确幸 2022-02-02 阅读 44
python
with open('xrdfile.txt', 'r', encoding='utf-8') as data:
    ls1 = []
    while True:
        tentative = data.readline()
        if tentative:
            line_to_ls = list(map(float, tentative.strip().split('	')))
            # print(line_to_ls)
            ls2 = [int(element) for element in line_to_ls]
            ls1.append(ls2)
            # print(ls1)
        else:
            break
n = int(input())
print(ls1[:n])
举报

相关推荐

0 条评论