Future Warning with Negative Int

Peter Otten __peter__ at web.de
Fri Apr 14 13:36:05 EDT 2006


brianlum at gmail.com wrote:

> If I try to print a negative integer as a hexadecimal, I get the
> following error:

>>>> print "%X" % -1
> __main__:1: FutureWarning: %u/%o/%x/%X of negative int will return a
> signed string in Python 2.4 and up
> FFFFFFFF
> 
> Does that mean that in the future it will say -1 or -FFFFFFFF?  

The future is now:

$ python2.4 -c 'print "%X" % -1'
-1

> Also, how do I suppress this warning?

With the -W option:

$ python2.3 -W ignore -c 'print "%X" % -1'
FFFFFFFF

or warnings.filterwarnings('ignore').

http://docs.python.org/lib/warning-functions.html

has more on the subject.

Peter





More information about the Python-list mailing list