Python学习:统计文本文件里某一字段出现的次数

统计文本字符串出现的次数很容易,用count函数。
先打开文件,读取文件,然后count计数。

file=open("D:\\pythonProject\\ICA_unittest\\result\\e2a6ac2c70d0407c8765260a921ce274.zip_files_33\\178790589_2020-12-23.txt")
txt=file.read()
count_num = txt.count("-- 2020-12-23")
file.close()
print(count_num)

猜你喜欢

转载自blog.csdn.net/sinat_37960022/article/details/111866869