python 读取文件生成嵌套列表

def read_data(file_name):
    if not re.findall(".txt", file_name):
        file_name += ".txt"
    L = [[] for h in [[] for k in range(5)]]
    with open(file_name) as r:
        for d in r:
            j = d.split("|")
            for i in range(len(L)):
                L[i].append(j[i].strip())
    return L

 

posted @ 2017-11-09 09:34  随便了888  阅读(1695)  评论(0编辑  收藏  举报