Skip to content

Instantly share code, notes, and snippets.

@deanlxvii
Created October 14, 2011 12:46
Show Gist options
  • Save deanlxvii/1287006 to your computer and use it in GitHub Desktop.
Save deanlxvii/1287006 to your computer and use it in GitHub Desktop.
Count the occurrences of a string in a file
def count(fileName, count_string):
"""
Count the occurrences of a string in a file
"""
count = 0
input = open(fileName, 'r')
line = input.readline()
while line <> '':
if count_string in line:
count = count + 1
return count
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment