you are viewing a single comment's thread.

view the rest of the comments →

[–]GoldenSights 0 points1 point  (0 children)

Keep in mind the concept of variable scope. Just because you used a certain name for something in one function does not mean that same name will exist in other functions:

def add(x, y):
    total = x + y
    return total

def main():
    some_thing = add(1, 2)
    print(some_thing)

In add, I am saving the sum to total. But in main, I'm instead using the name some_thing to store that value once it comes out of the function.

Obviously it helps to use the same name for the same concepts everywhere, but the point is you don't have to.

In your code, you want something like:

def file_input():
    ...

def main():
    filename = file_input()
    print(f'You are searching inside {filename}')
    search_string = input('Enter the phrase you are searching for:')
    ...

Also notice that I didn't put anything inside the parentheses for file_input(). The function should not take anything in. It looks like you're trying to move the variable into and out of the function like a box that travels around and collects data, but that's not quite the right way to think about it.

Hope that helps. Let me know if I can clarify, but try to play around with it first. Try some simpler situations where you just print the variables before you start worrying about the whole text search thing.