Disagree with proposed 2.4 behavior for %x formatting of signed i nts

Tim Roberts timr at probo.com
Tue Sep 9 02:24:11 EDT 2003


"Letbetter, Jason" <letbetter at ti.com> wrote:
>
>Consider the following:
>
>>>> print "0x%08X" % -1041053949
>__main__:1: FutureWarning: %u/%o/%x/%X of negative int will return a signed
>string in Python 2.4 and up
>0xC1F2C703
>
>If I understand the warning correctly then the following would happen after
>2.4:
>
>>>> print "0x%08X" % -1041053949
>-1041053949

You do not understand correctly.  This is what will happen:

>>> print "0x%08X" % -1041053949
0x-3E0D38FD

It will still be a hex number, but the sign will be honored, producing
possibly unexpected results.

>I think the printf format should take precedence.  It is obvious that the
>programmer wants a hex number displayed.

You'll get a hex number.  You'll just get a sign with it.

I've started three different times to post a message complaining that the
changes in 2.3 and the changes proposed in 2.4 are taking Python farther
and farther away from the cool system-level binary manipulation tool I
often use it for, but every time I get part way through it, I realize that
the changes do make sense from a consistency point of view, and that it
doesn't take that much more work to do it "right".
-- 
- Tim Roberts, timr at probo.com
  Providenza & Boekelheide, Inc.




More information about the Python-list mailing list