[Python-Dev] str with base

Gisle Aas gisle at ActiveState.com
Wed Jan 18 08:35:26 CET 2006


Jack Diederich <jack at performancedrivers.com> writes:

> > However... if %b were to represent arbitrary bases, I think that's  
> > backwards.  It should be %[<pad>][.<base>]b, which would do this:
> > 
> > 	>>> '%08b %08o %08d %08x' % 12
> > 	'00001100 00000014 00000012 0000000C'
> > 
> 
> Were I BDFAD (not to be confused with BD-FOAD) I'd add %b, %B and, binary()
> to match %x, %X, and hex().  The arbitrary base case isn't even academic
> or we would see homework questions about it on c.l.py.  No one asks about
> hex or octal because they are there.  No one asks about base seven
> formatting because everyone knows numerologists prefer Perl.

BTW, Perl already do binary literals and %b formatting so there is
some precedence for it:

  $ perl -e '$a = 0b1100; printf "%08b %08o %08d %08x\n", $a, $a, $a, $a'
  00001100 00000014 00000012 0000000c  

--Gisle


More information about the Python-Dev mailing list