2017-07-26 04:37:36 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
from __future__ import absolute_import
|
2017-07-23 05:32:18 +00:00
|
|
|
|
2018-07-30 20:52:22 +00:00
|
|
|
from .word_count import WordCounter, count_line
|
2017-07-26 04:37:36 +00:00
|
|
|
|
2018-07-30 20:52:22 +00:00
|
|
|
__all__ = ["WordCounter", "count_line", "search_py"]
|
2017-07-26 04:37:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
def search_py(path, needle):
|
|
|
|
total = 0
|
2018-07-30 20:52:22 +00:00
|
|
|
with open(path, "r") as f:
|
2017-07-26 04:37:36 +00:00
|
|
|
for line in f:
|
2018-07-30 20:52:22 +00:00
|
|
|
words = line.split(" ")
|
2017-07-26 04:37:36 +00:00
|
|
|
for word in words:
|
|
|
|
if word == needle:
|
|
|
|
total += 1
|
|
|
|
return total
|