2005年06月19日 星期日 13:44
就以这样的数据文本为例的话,可以简单的构造你期望的数据对象然后过滤
data.txt
import os,sys
# 读入信息为行数据数组
data = open("data.txt","r").readlines()
# 我们期望的数据容器
matrix = []
# 标识哪行数据
type = 0
for line in data:
print line
dataline = line.split()
i = 0
for item in range(2,len(dataline)):
if 0==type:
matrix.append([dataline[item],])
else:
matrix[i].append(dataline[item])
i +=1
type +=1
# 我们想要的数据
export = []
for item in matrix:
if "0x0000"==item[2]:
pass
else:
export.append(item)
print export
其实就是转换文本为数据对象然后处理是也乎!
在 05-6-19,Zhongwang Xu<zhongwangxu at gmail.com> 写道:
> 不好意思,我是新手,能否说的详细一点,多谢了。
>
> 比如,我要在文本格式的数据中,找出相关的有用数据,再根据特定的形式,
> 存入另外一个文件。
>
> 数据例子:
>
> Event : 0x0111 0x1020 0x4024 0x4027 0x1022 0x1029 0x1030 0x2031 0x2032
> Code : 0x0000 0x0000 0x0003 0x0000 0x0000 0x0004 0x0000 0x0003 0x0000
> State : 0x0000 0x0000 0x00EE 0x0000 0x0000 0x00EF 0x0000 0x00E9 0x0000
>
> 我要找出在 Code 行中,不为0的数据,并纪录下这个数据想对应的State.
>
> 存入格式:
>
> 0x0003 0x00EE
> 0x0004 0x00EF
> 0x0003 0x00E9
>
> 再次感谢!
>
--
[Time is unimportant, only life important!]
2005年06月19日 星期日 13:46
补充: 最后已经将有效数据组织为一个数据, 如果组织格式写到文件中就非常简单了,就不用我来罗嗦了是也乎………… 在 05-6-19,Zoom Quiet<zoom.quiet at gmail.com> 写道: > 就以这样的数据文本为例的话,可以简单的构造你期望的数据对象然后过滤 > data.txt > > import os,sys > # 读入信息为行数据数组 > data = open("data.txt","r").readlines() > # 我们期望的数据容器 > matrix = [] > # 标识哪行数据 > type = 0 > for line in data: > print line > dataline = line.split() > i = 0 > for item in range(2,len(dataline)): > if 0==type: > matrix.append([dataline[item],]) > else: > matrix[i].append(dataline[item]) > i +=1 > type +=1 > # 我们想要的数据 > export = [] > for item in matrix: > if "0x0000"==item[2]: > pass > else: > export.append(item) > print export > > 其实就是转换文本为数据对象然后处理是也乎! > > > 在 05-6-19,Zhongwang Xu<zhongwangxu at gmail.com> 写道: > > 不好意思,我是新手,能否说的详细一点,多谢了。 > > > > 比如,我要在文本格式的数据中,找出相关的有用数据,再根据特定的形式, > > 存入另外一个文件。 > > > > 数据例子: > > > > Event : 0x0111 0x1020 0x4024 0x4027 0x1022 0x1029 0x1030 0x2031 0x2032 > > Code : 0x0000 0x0000 0x0003 0x0000 0x0000 0x0004 0x0000 0x0003 0x0000 > > State : 0x0000 0x0000 0x00EE 0x0000 0x0000 0x00EF 0x0000 0x00E9 0x0000 > > > > 我要找出在 Code 行中,不为0的数据,并纪录下这个数据想对应的State. > > > > 存入格式: > > > > 0x0003 0x00EE > > 0x0004 0x00EF > > 0x0003 0x00E9 > > > > 再次感谢! > > > > -- > [Time is unimportant, only life important!] > -- [Time is unimportant, only life important!]
Zeuux © 2025
京ICP备05028076号