python查找文件中某个字符串出现的次数

'''查找文件中某个字符串总共出现的次数'''
def findStr(str):
with open("filePath",'r') as f:
counts = 0
for line in f.readlines():
time = line.count(str)
counts += time
print("%s出现的次数:%d"%(str,counts))

findStr("str")

posted on 2020-12-01 18:41  小白在此  阅读(6107)  评论(0编辑  收藏  举报

导航