Does Python need a '>>>' operator?

Just van Rossum just at xs4all.nl
Mon Apr 15 11:41:52 EDT 2002


In article <3cbaefb5 at news.mhogaming.com>,
 "Ken Peek" <Ken.Peek at SpiritSongDesigns.comNOSPAM> wrote:

> When printing hexadecimal numbers, the bit pattern is what is needed-- not the
> sign and magnitude.

Here's a snippet from the CVS log of intobject.c:
----------------------------
revision 2.28
date: 1997/01/12 19:48:03;  author: guido;  state: Exp;  lines: +2 -7
Changed hex() and oct() again, to never emit a '-' sign.
----------------------------

I vaguely remember that hex(-1) indeed once printed -0x1, and that this 
was later fixed. Ah, the diff from 2.27 to 2.28 shows that this is 
indeed the case:


Index: intobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/intobject.c,v
retrieving revision 2.27
retrieving revision 2.28
diff -c -r2.27 -r2.28
*** intobject.c 10 Jan 1997 17:39:30 -0000      2.27
--- intobject.c 12 Jan 1997 19:48:03 -0000      2.28
***************
*** 725,734 ****
        long x = v -> ob_ival;
        if (x == 0)
                strcpy(buf, "0");
-       else if (-x < 0)
-               sprintf(buf, "0%lo", x);
        else
!               sprintf(buf, "-0%lo", -x);
        return newstringobject(buf);
  }
  
--- 725,732 ----
        long x = v -> ob_ival;
        if (x == 0)
                strcpy(buf, "0");
        else
!               sprintf(buf, "0%lo", x);
        return newstringobject(buf);
  }
  
***************
*** 738,747 ****
  {
        char buf[20];
        long x = v -> ob_ival;
!       if (-x <= 0)
!               sprintf(buf, "0x%lx", x);
!       else
!               sprintf(buf, "-0x%lx", -x);
        return newstringobject(buf);
  }
  
--- 736,742 ----
  {
        char buf[20];
        long x = v -> ob_ival;
!       sprintf(buf, "0x%lx", x);
        return newstringobject(buf);
  }
  



Just



More information about the Python-list mailing list