Created
October 14, 2011 12:46
-
-
Save deanlxvii/1287006 to your computer and use it in GitHub Desktop.
Count the occurrences of a string in a file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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