I have a text file containing this:
Pacemakers, neurotechnology, nanoparticles, and interpretation of medical images -
with the combination of knowledge in mathematics, physics, and technology,
you can be involved in developing medical technology that can save lives and improve human
health.
Developments in medical technology are going furiously fast and "engineering for health"
is becoming increasingly important. As a civil engineer in medical technology,
you get to participate in the development of medical science.
You create the tools that process data from computed tomography, MRI cameras, and bio-optical
sensors into a form that the doctor can interpret; which combines technology with the body's
functions and which explores new areas of application in health, environment, and sports.
What I am trying to do is to write a code that will search for a word, and the output will be on which row the code is on. For example, if I want to search for "pacemaker" then the output will be "1" because it's on that row, and so on.
I was thinking maybe the code could look for every "\n" in the file, and whenever it finds it, it increases a counter by 1, so I can keep track of which row. And when the word is found I just return the value of the counter.
I tried something like this:
def find_row(word):
counter = 0
with open(self.text,"r",encoding="utf-8") as a_file:
for line in a_file:
if word == a_file:
if keyword == "\n":
counter += 1
However, I feel like this logic is completely backward, I really don't know how to proceed from here.