Assign line from .txt file to a variable python for later use
<p>I have 2 defined functions in which both need to use a line from a text file that is found. However because they are two different functions i can't use "line" in the one which doesn't search the text file for that line. So i want to take the value of "line" which was found and assign it to a variable to use in the later functions but i get the error that "variable_Line" is not defined.</p>

<p>Section of first function:</p>

<pre><code>while (len(code) == 8):
    with open('GTIN Products.txt', 'r') as search:
        for line in search:
            line = line.rstrip('\n')
            if code in line:
                variable_Line = line #This is where i try to assign contents to a variable

                print("Your search found this result: "+line) #this prints the content of line 

                add_cart() #second function defined below
</code></pre>

<p>Second function</p>

<pre><code>def add_cart():
    add_cart = ""
    while add_cart not in ("y", "n"):
        add_cart = input("Would you like to add this item to your cart? ")
        if add_cart == "y":
            receipt_list.append(variable_Line) #try to use the variable here but get an error

        if add_cart == "n":
            break
</code></pre>