【发布时间】:2018-03-25 13:13:21
【问题描述】:
我想使用re.findall 来检测一个单词在 .txt 文件中显示了多少次。另外,如果我要计算 Hello 一词出现在要检测的文本 Hellooo 中的次数,我还需要它。 p>
这是我所有的代码:
# -*- coding: utf-8 -*-
import re
total = 0
with open('text.txt') as f:
for line in f:
total = re.findall('Hello')
print total
【问题讨论】:
-
您似乎忘记在问题中提出问题。请红色How to Ask并提供minimal reproducible example。
标签: python regex python-2.7