why doesn't this filter the warning?

Terry Carroll carroll at tjc.com
Sun Oct 17 21:18:06 EDT 2004


If I do the following code, whether in the interactive session or in a
file, I get a FutureWarning:

>>> x = 0xffffffff
<stdin>:1: FutureWarning: hex/oct constants > sys.maxint will return
positive values in Python 2.4 and up

Okay; that's expected.  No problem, I'll just turn off the
FutureWarning.  Here's the results from within an interactive session:

>>> import warnings
>>> warnings.filterwarnings('ignore', "hex/oct constants", FutureWarning)
>>> x = 0xffffffff

Note that no warning is produced.  Great; that's what I wanted.

But now, the same thing, but executing a file, rather than
interactively:

[begin-quote]
C:\test\misc>cat testfw.py
import warnings
warnings.filterwarnings('ignore', "hex/oct constants", FutureWarning)
x = 0xffffffff

C:\test\misc>python testfw.py
testfw.py:3: FutureWarning: hex/oct constants > sys.maxint will return
positive values in Python 2.4 and up
  x = 0xffffffff
[end-quote]

Why won't the filterwarnings call suppress this?




More information about the Python-list mailing list