Friday, August 14, 2015

Python: Count the number of times a string is present in a file


import string
text = open(fname).read()
print string.count(text, 'the_string')

No comments: