[Tutor] :0: SyntaxWarning: name 'VAR' is assigned to before global declaration

Marilyn Davis marilyn at deliberate.com
Sun Jun 27 19:54:05 EDT 2004


Hello again Python experts!

I ran across this warning:

#!/usr/bin/env python2.3
VAR = 'xxx'

if __name__ == '__main__':
    global VAR
    VAR = 'yyy'

---

OUTPUT:

./var.py:0: SyntaxWarning: name 'VAR' is assigned to before global declaration

----

But, a little twiddle quiets the warning, and I have no idea why:

#!/usr/bin/env python2.3
VAR = 'xxx'

def set_var():
    global VAR
    VAR = 'yyy'    

if __name__ == '__main__':
    set_var()
    
---

No output.

Can anyone explain what is happening?

Thank you.

Marilyn Davis

-- 





More information about the Tutor mailing list