Help with syntax warnings

Fredrik Lundh fredrik at pythonware.com
Sat Oct 1 10:52:22 EDT 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?

fix your code.

fixing syntaxwarnings is almost always trivial; most of the time, all you
have to do is to remove (or rephrase) some statement that doesn't do
what you think it does anyways...

if you really cannot motivate yourself to fix your code, you have to add
an extra "bootstrap" module.  if your program is named "myprogram.py",
rename that file to "myactualprogram.py", and add a "myprogram.py" that
looks like this:

    # File: myprogram.py

    import warnings
    warnings.simplefilter("ignore", SyntaxWarning)
    import myprogram

(you may have to fix any __name__ == "__main__" clauses in your original
program).

but you really should fix your program, instead of wasting time on stupid
workarounds.

</F>






More information about the Python-list mailing list