'''查找文件中某个字符串总共出现的次数'''
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")
'''查找文件中某个字符串总共出现的次数'''
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")
本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。