python 读取文件生成嵌套列表

Posted 吴悟无

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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

 

以上是关于python 读取文件生成嵌套列表的主要内容,如果未能解决你的问题,请参考以下文章