Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

warnings filter?

96 views
Skip to first unread message

r...@encodia.biz

unread,
Jul 8, 2004, 10:10:50 AM7/8/04
to
In Python 2.3, this code still prints a warning (when run as a script,
not from the interpreter). How do I get rid of the warning? I'd like
to do it without passing command line args to python.

import warnings
warnings.filterwarnings('ignore')
a = 0xffffffff


Thanks,
Rob

Peter Otten

unread,
Jul 9, 2004, 3:33:04 PM7/9/04
to
r...@encodia.biz wrote:

The warning is issued during the compilation, not the execution of your
script. Therefore the attempt to turn off the warning, although before the
offensive statement, comes too late.

<offensive.py>
a = 0xffffffff
</offensive.py>

One workaround is to precompile offensive.py (By the way is there a flag to
do this that I've overlooked?):

$ python -c"import offensive"
offensive.py:1: FutureWarning: hex/oct constants > sys.maxint will return
positive values in Python 2.4 and up
a = 0xffffffff


and then invoke offensive.pyc:

$ python offensive.pyc

All quiet :-)

The other option would be to reorganize your script to the same effect.

$ rm offensive.pyc
$ python driver.py
$

Where driver looks like so:

<driver.py>
import warnings
warnings.filterwarnings('ignore') # should probably be more specific

import offensive
</driver>

Of course you could omit the first two lines when you can live with a
warning the first time you run driver.py after every change of
offensive.py.

Peter


0 new messages