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

GSatterwhite
  • 301
  • 1
  • 3
  • 12

1 Answers1

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.

lmiguelvargasf
  • 63,191
  • 45
  • 217
  • 228