473,398 Members | 2,125 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

warnings filter?

rob
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
Jul 18 '05 #1
1 2205
ro*@encodia.biz wrote:
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


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


Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Kylotan | last post by:
I have the following code: def IntToRandFloat(x): """Given a 32-bit integer, return a float in """ x = int(x) x = int(x << 13) ^ x return...
2
by: Torsten Bronger | last post by:
Hallöchen! When I add a warning filter with warnings.filterwarnings, how can I get rid of it? I've read about resetwarnings(), but it removes all filters, even those that I didn't install in a...
12
by: Gary | last post by:
Hi! guys, I have a SQL agent job fails because it gets 10 warnings when it runs a stored procedure. These warnings are trivial and can be ignored. Can I make it ignore these warnings and...
3
by: Terry Richards | last post by:
mysql 4.1.9-standard how do i find exactly what the warnings are when i only get Query OK, 1 row affected, 1 warning (0.00 sec) :-)^2
22
by: John Fisher | last post by:
void f(int p) { } Many (most?) compilers will report that p is unreferenced here. This may not be a problem as f may have to match some common prototype. Typically pointers to functions are...
6
by: pete142 | last post by:
When I compile this code: typedef unsigned char BYTE; BYTE * IpString(unsigned int ip) { static BYTE ipString; ipString = (BYTE) 0xff & (ip >24); ipString = (BYTE) 0xff & (ip >16);
3
by: gil | last post by:
Hi, I'm trying to find the best way to work with compiler warnings. I'd like to remove *all* warnings from the code, and playing around with the warning level, I've noticed that compiling with...
1
by: Robert Singer | last post by:
Platform: winXP, excel 2003 Python 2.5.2 XLWriter 0.4a3 (http://sourceforge.net/projects/pyxlwriter/) Is anyone here using this very nice package, for writing excel files? I'm using it on...
7
by: Grant Edwards | last post by:
<rant> I'm getting awfully tired of constant warnings about what's going to happen at some point in the future. Warnings like this: ./surfplot.py:313: Warning: 'with' will become a reserved...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.