with open('C:\\Users\\Lenovo\\Desktop\\2.txt', 'rb') as f:
count = 0
for line in f:
if b'12661' in line:
count += line.count(b'12661')
print("The element '12661' appears", count, "times in the file.")
python脚本统计某个文件中出现的字符串的次数
于 2023-04-24 13:37:35 首次发布