Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RichardEllicott/6fb57a943f47dc712c82a55240e066b8 to your computer and use it in GitHub Desktop.
Save RichardEllicott/6fb57a943f47dc712c82a55240e066b8 to your computer and use it in GitHub Desktop.
import sys
filename = sys.argv[1] # first argument
string_to_count = sys.argv[2] # second argument
with open(filename) as f: # opens a file, f becomes the file object, this is the official PEP8 style for reading files
text = f.read() # we need to read the data from that file
print(text.count(string_to_count)) # strings have a special function in python that can count the occurrences of a string within them
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment