本文整理汇总了Python中searcher.Searcher.search_for_pattern方法的典型用法代码示例。如果您正苦于以下问题:Python Searcher.search_for_pattern方法的具体用法?Python Searcher.search_for_pattern怎么用?Python Searcher.search_for_pattern使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类searcher.Searcher
的用法示例。
在下文中一共展示了Searcher.search_for_pattern方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: file
# 需要导入模块: from searcher import Searcher [as 别名]
# 或者: from searcher.Searcher import search_for_pattern [as 别名]
args_parser = argparse.ArgumentParser(description='Search all files in a '
'directory (including subdirectories) '
'for a regex pattern')
args_parser.add_argument('-p', '--regex-pattern', help='regex pattern to '
'search for in the file(s) in the directory',
required=True)
args_parser.add_argument('-o', '--output-file', nargs='?', help='path to the '
'output file where all matching lines will be written'
' to', default='matches.txt', type=str)
args_parser.add_argument('-d', '--directory', nargs='?', type=str,
help='directory of file(s) which will be scanned',
default='./')
args = args_parser.parse_args()
searcher = Searcher()
start_time = time.time()
count = 0
result = searcher.search_for_pattern(args.directory, args.regex_pattern)
with open(args.output_file, 'w+b') as file:
for res in result:
count += len(res)
file.writelines(res)
end_time = time.time()
print('time elapsed:')
utils.print_elapsed_time(start_time=start_time, end_time=end_time)
print('#### found {0!s} matching line(s) ####'.format(count))
print('done!')