How do I avoid this global SyntaxWarning?
bsb at winnegan.de
Sat Aug 25 18:25:45 CEST 2001
gradha at iname.com writes:
> Promptly most of my scripts give SyntaxWarnings under Python 2.1.1, and the
> warning is so strange to me, and doesn't explain anything or point in any
> direction that I don't know exactly what to do. I've searched the
> documentation for warning, syntax and global keywords, but I don't seem to
> find what is making python angry. Here's the example:
> #!/usr/bin/env python
> expresion_include = "a string"
> if __name__ == "__main__":
> global expresion_include
> print expresion_include
> As said before, versions of Python 2.0 and earlier didn't show this warning.
> What is it
SyntaxWarning: name 'expresion_include' is assigned to before global declaration
Exactly what it says, in line 3 you assigned to expresion_include,
later in line 6 you declare it global.
> and how do I make it go away?
Remove the global statement, at module scope it doesn't make sense.
Siggy Brentrup - bsb at winnegan.de - http://oss.winnegan.de/
More information about the Python-list