python 查找文件中某个字符串个数
#!/usr/bin/env python# -*- encoding: utf-8 -*-'''@文件:findstr.py@说明:@时间:2021/07/08 10:29:37@作者:shitao.li@版本:1.0'''def findStr(str):with open("a.txt",'r') as f:counts = 0for line in f..
·
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@文件 :findstr.py
@说明 :
@时间 :2021/07/08 10:29:37
@作者 :shitao.li
@版本 :1.0
'''
def findStr(str):
with open("a.txt",'r') as f:
counts = 0
for line in f.readlines():
time = line.count(str)
counts += time
print("%s出现的次数:%d"%(str,counts))
findStr(",")
更多推荐
已为社区贡献5条内容
所有评论(0)