统计文件中某一字符串出现的次数

f1=file("hello.txt")
count=0
s=f1.read()
li=re.findall("hello",s)
if len(li)>0:
    count=count+li.count("hello")
print str(count)
f1.close()

 

posted @ 2010-01-23 23:36  HeartLight  阅读(243)  评论(0编辑  收藏  举报