码迷,mamicode.com
首页 > 编程语言 > 详细

python 读取文件生成嵌套列表

时间:2017-11-09 11:21:34      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:for   data   findall   txt   turn   嵌套   读取文件   with open   blog   

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 读取文件生成嵌套列表

标签:for   data   findall   txt   turn   嵌套   读取文件   with open   blog   

原文地址:http://www.cnblogs.com/vickey-wu/p/7807858.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!