Future Warning with Negative Int

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • brianlum@gmail.com

    #1

    Future Warning with Negative Int

    Hi,

    If I try to print a negative integer as a hexadecimal, I get the
    following error:
    FutureWarning: %u/%o/%x/%X of negative int will return a signed string
    in Python 2.4 and up

    For example:[color=blue][color=green][color=darkred]
    >>> print "%X" % -1[/color][/color][/color]
    __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? Also,
    how do I suppress this warning?

    Thanks,
    Brian

  • Peter Otten

    #2
    Re: Future Warning with Negative Int

    brianlum@gmail. com wrote:
    [color=blue]
    > If I try to print a negative integer as a hexadecimal, I get the
    > following error:[/color]
    [color=blue][color=green][color=darkred]
    >>>> print "%X" % -1[/color][/color]
    > __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?[/color]

    The future is now:

    $ python2.4 -c 'print "%X" % -1'
    -1
    [color=blue]
    > Also, how do I suppress this warning?[/color]

    With the -W option:

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

    or warnings.filter warnings('ignor e').



    has more on the subject.

    Peter


    Comment

    Working...