1

I am having trouble assigning a variable as global (i think this is my problem, at least).

Heres a representation of my code:

def get_alert(): 

    global subject

    # ...code ... 

    subject = # unread email's subject line 


while True:

    try:

        get_alert()

    except EOFError:

        get_alert() # try again    

    else:

        if subject == 'specific message here'

            # ...code...

From what i've read assigning the variable as global at the top of the get_alert function should allow me to reference it in the while loop, however running the program it tells me, 'NameError: name 'subject' is not defined' for the subject in the while loop

1
  • You should return it instead. Commented Apr 17, 2019 at 15:08

1 Answer 1

1

You have to define subject before you use it, if you add

subject = None

at the beginning of your script, preferable after the imports, I think that will work.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.