I have tried to create a python function which takes in 2 parameters; a file name and a search string. In this case the file name is the script itself (script.py) and the searc
You are iterating over each character of the file by calling for c in f.read().
for c in f.read()
Use for line in f and you will indeed iterate over each line.
for line in f
Also prefer the use of with, this makes your code a lot more robust.
with
So this would be better:
with open('fileName') as f: for line in f: #process