Help with syntax warnings

Peter Otten __peter__ at web.de
Sat Oct 1 18:47:54 CEST 2005


Ivan Shevanski wrote:

> Well I've been experimenting with the warning filter and it doesn't seem
> to be working. . .I think it has something to do with the fact that
> warnings are issued during the compiling and not during the excecution. .
> .So the filter would come in to late to block them? Any ideas?

$ cat syntaxwarning.py
def f():
    x = 42
    global x
$ python2.4 syntaxwarning.py
syntaxwarning.py:1: SyntaxWarning: name 'x' is assigned to before global
declaration
  def f():

Method 1: precompile the py-file and then invoke the compiled variant:

$ python2.4 -c 'import syntaxwarning'
syntaxwarning.py:1: SyntaxWarning: name 'x' is assigned to before global
declaration
  def f():
$ python2.4 syntaxwarning.pyc

Method 2: switch off the warning:

$ python2.4 -Wignore::SyntaxWarning syntaxwarning.py

Peter




More information about the Python-list mailing list