python脚本统计某个文件中出现的字符串的次数


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)