def read_data(file_name):
if not re.findall(".txt", file_name):
file_name += ".txt"
L = [[] for h in [[] for k in range()]]
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 读取文件生成嵌套列表的更多相关文章

  1. python 读取文件时报错UnicodeDecodeError: 'gbk' codec can't decode byte 0x80 in position 205: illegal multibyte sequence

    python读取文件时提示"UnicodeDecodeError: 'gbk' codec can't decode byte 0x80 in position 205: illegal m ...

  2. 解决 python 读取文件乱码问题(UnicodeDecodeError)

    解决 python 读取文件乱码问题(UnicodeDecodeError) 确定你的文件的编码,下面的代码将以'utf-8'为例,否则会忽略编码错误导致输出乱码 解决方案一 with open(r' ...

  3. python 读取文件read.csv报错 OSError: Initializing from file failed

    小编在用python 读取文件read.csv的时候 报了一个错误 OSError: Initializing from file failed 初始化 文件失败 检查了文件路径,没问题 那应该是我文 ...

  4. python 读取文件时报错UnicodeDecodeError: 'gbk' codec can't decode byte 0x80 in position 205: illegal multib

    python 读取文件时报错UnicodeDecodeError: 'gbk' codec can't decode byte 0x80 in position 205: illegal multib ...

  5. Python 读取文件中unicode编码转成中文显示问题

    Python读取文件中的字符串已经是unicode编码,如:\u53eb\u6211,需要转换成中文时有两种方式 1.使用eval: eval("u"+"\'" ...

  6. python读取文件首行和最后一行

    python读取文件最后一行两种方式 1)常规方法:从前往后依次读取 步骤:open打开文件. 读取文件,把文件所有行读入内存. 遍历所有行,提取指定行的数据. 优点:简单,方便 缺点:当文件大了以后 ...

  7. python操作txt文件中数据教程[3]-python读取文件夹中所有txt文件并将数据转为csv文件

    python操作txt文件中数据教程[3]-python读取文件夹中所有txt文件并将数据转为csv文件 觉得有用的话,欢迎一起讨论相互学习~Follow Me 参考文献 python操作txt文件中 ...

  8. 【python】python读取文件报错UnicodeDecodeError: 'gbk' codec can't decode byte 0xac in position 2: illegal multibyte sequence

    python读取文件报错UnicodeDecodeError: 'gbk' codec can't decode byte 0xac in position 2: illegal multibyte ...

  9. python 读取文件时报错: UnicodeDecodeError: 'gbk' codec can't decode byte 0xa4 in position 127: illegal multibyte sequence

    UnicodeDecodeError: 'gbk' codec can't decode byte 0xa4 in position 127: illegal multibyte sequence p ...

随机推荐

  1. Linux网络协议栈(三)——网络设备(2)

    2.1.网络设备的注册与注销注册网络设备发生在下列情形: (1)加载网卡驱动程序   网卡驱动程序如果被编译进内核,则它在启动时被初始化,在运行时被作为模块加载.无论初始化是否发生,所以由驱动程序控制 ...

  2. 详解Python的*args和 **kwargs

    转自: http://www.python[tab].com/html/2016/pythonhexinbiancheng_0802/1057.html *args表示任何多个无名参数,它是一个tup ...

  3. ruby gem的安装步骤

    第一步:下载安装文件 官网下载地址:http://rubyinstaller.org/downloads 第二步: 双击安装 在安装的时候,请勾选Add Ruby executables to you ...

  4. Pow(x, n) 位运算总结 典型

    https://leetcode.com/problems/powx-n/ Implement pow(x, n), which calculates x raised to the power n  ...

  5. arcgis for silverlight 相关学习资料整理

    Arcgis Resources:http://resources.arcgis.com/en/home/ esri中文官方论坛:http://www.gisall.com/portal.php 爱吃 ...

  6. 微信公众平台——基础配置——服务器配置:PHP版

    在自己的服务器上新建一个空白php文件,输入以下任一版本的代码,如下: 版本一: <?php $token = "dige1994"; $signature = $_GET[ ...

  7. poj2676 Sudoku(搜索)

    题目链接:http://poj.org/problem?id=2676 题意:9*9的方格,0代表没数字,其他代表数字,请在格子中填入1~9的数字,使得在每行,每列和每个3*3的方块中,1~9的数字每 ...

  8. Ruby  Hash类

    Hash类 更新:2017/06/15 获取没有的哈希值时返回nil 更新:2018/01/03 增加merge! 更新: 2018/04/05 增加搜索 key 更新: 2018/04/30 增加e ...

  9. sql server 分组排序

    环境: sql server 2012 语法 select ROW_NUMBER() over(partition BY 分组字段 order by 排序字段),* as rowNums from 表 ...

  10. CI框架中一个类中调用另一个类中已经加载对象测试

    controller.php <?php class CI_Controller { private static $instance; public function __construct( ...