Skip to content

Instantly share code, notes, and snippets.

@wohhie
Created July 25, 2016 17:34
Show Gist options
  • Save wohhie/53b84217f0973bab7ca51228a4d9d7cf to your computer and use it in GitHub Desktop.
Save wohhie/53b84217f0973bab7ca51228a4d9d7cf to your computer and use it in GitHub Desktop.
❋ File Open ❋ Read the file ❋ Count Number of char with user choice -------EXAMPLE------
#count_char method.
#which count the total value
def count_char(text, char):
count = 0
for c in text:
if( c == char):
count += 1
return count;
#insert filename
filename = str(raw_input("Enter filename: "))
#read data
with open(filename) as data:
text = data.read();
#print data
#print(text);
#search for the value
count = str(count_char(text, "v"))
print("Counted value: " + count)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment