写了段文本处理的python代码,请教点问题

ganmu 2012-07-02 03:57:49
import os
import sys
import string
import getopt
import re
f=open('xx.log','r+')
for s in f.readlines():
temps=string.splitfields(s, '|')
print re.findall('dev',temps[1])
if re.findall('beta|dev',temps[1]):
print s
f.close


以上我是要用re.findall的结果来做一个判断,如果匹配到了就打印s的值?为什么不成功呢?求解!
...全文
48 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
bugs2k 2012-07-02
  • 打赏
  • 举报
回复
#!/usr/bin/env python

import re

f=open('xx.log','r+')
for s in f:
temps = s.split('|')
print re.findall('dev', temps[1])
if re.findall('beta|dev', temps[1]):
print s
f.close
ganmu 2012-07-02
  • 打赏
  • 举报
回复
我擦,还真是,python对缩进要求这么严格的,我晕!多谢楼上。
ganmu 2012-07-02
  • 打赏
  • 举报
回复
对吧,我这测试都正常啊。
zengna_com 2012-07-02
  • 打赏
  • 举报
回复
后面那个if缩进不对啊

37,721

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧