使用python读取文本中结构化数据
2017-03-06 21:04
591 查看
需求
read some .txt file in dir and find min and max num in file.
solution:
echo *.txt > file.name in linux shell >>>execfile(“mytest.py”); //equivalent to run mytest.m in matlab import os fileobj = open("./test2images/2d_xxx.name"); filestring = fileobj.readline(); //line is a list stored all .txt name filestring = filestring.split(); dir = './test2images/' x = []; y = []; for i in filestring: dataname = open(dir + i); for j in range(1,15): data = dataname.readline(); if not data: break; data = data.strip('\r\n'); data = data.split(); //It will split the long string line as a list of strings x.append(int(data[0])); y.append(int(data[1])); print min(x) print min(y) //normal structure of while circulation # while 1: # data = dataname.readline(); # if not data: # break;
读写中英文参杂的文本
str.decode('utf8') #str先使用utf8的方式解码,得到每个汉字为一个字符 str.encode('utf8') #保存str到文件之前,先使用utf8的方式编码,再存储
相关文章推荐
- python pickle模块使用-将内存数据保存到文本中以及从文本中直接读取信息到内存中
- 使用python读取csv文件,并将数据更新至mysql
- Python读取PostgreSQL数据并使用基于物品的协同过滤算法计算推荐结果
- python读取数值文本数据比较--一般读取方式 Vs numpy
- 使用python pandas读取csv文件数据
- 使用python读取数据科学最常用的文件格式
- asp.net 解决使用OLEDB导入excel数据时同时包含文本和数字的列无法正常读取情况
- Delphi中使用python脚本读取Excel数据
- python读取文本数据写入到数据库及查询优化
- python使用h5py读取mat文件数据,并保存图像
- 使用kafkapython读取实时数据小例子
- python读取文本、配对、插入数据脚本
- MySQL中游标使用以及读取文本数据
- 使用python读取tensorflow实例中的MNIST模拟数据
- net控件中数据导到Excel的格式 首先,我们了解一下excel从web页面上导出的原理。当我们把这些数据发送到客户端时,我们想让客户端程序(浏览器)以excel的格式读取它,所以把mime类型设为:application/vnd.ms-excel,当excel读取文件时会以每个cell的格式呈现数据,如果cell没有规定的格式,则excel会以默认的格式去呈现该cell的数据。这样就给我们提供了自定义数据格式的空间,当然我们必须使用excel支持的格式。下面就列出常用的一些格式: 1) 文本
- MySQL中游标使用以及读取文本数据
- 使用Python将TXT文本内容读取后生成指定XML格式的文件
- 使用Python与openpyxl进行表格处理(一)——读取数据
- python读取GB级的文本数据,防止memoryError
- 【Python_Demo_2】使用Python连续(批量)读取图片数据的Demo