2005年06月20日 星期一 15:29
我是刚学python,看了好长时间终于看懂了,看到一个小问题,他是要根据code行判断,应该是if "0x0000"==item[1]: 而不是2吧,呵呵。算是第一次发言了。
======== 2005-06-19 13:44:24 您在来信中写道: ========
就以这样的数据文本为例的话,可以简单的构造你期望的数据对象然后过滤
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!]
_______________________________________________
python-chinese list
python-chinese at lists.python.cn
http://python.cn/mailman/listinfo/python-chinese
= = = = = = = = = = = = = = = = = = = = = =
致
礼!
顾英博
tensiongyb at 163.com
2005-06-20
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20050620/b3043995/attachment.htm
Zeuux © 2025
京ICP备05028076号