<br><div class="gmail_quote">On Fri, Dec 2, 2011 at 4:12 PM, T.B. <span dir="ltr"><<a href="mailto:bauertomer@gmail.com">bauertomer@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">


  

    
  
  <div style="direction:ltr" bgcolor="#FFFFFF" text="#000000">
    <p>I suggest using the precision field in the format specification
      for integers for that. Examples:</p>
    <p>"{:.16d}".format(31) #Prints '1f'</p>
    <p>"{:.2d}".format(-19) # Prints '-10011'</p><font color="#888888">
    </font><p><snip></p></div></blockquote><div>I don't think this belongs in format.</div></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

<div style="direction:ltr" bgcolor="#FFFFFF" text="#000000"><p>
    </p>
    <p>P.S. Bonus question: What "{:.-909d}".format(42) would print?</p></div></blockquote><div>Any proposal which includes an inscrutable example doesn't bode well for the usability of the feature. :-) Sure, negative bases are mathematically meaningful but are they useful in Python? And why not complex bases then? Or did you have something else strange in mind?</div>

</div><div><br></div><div>If there's enough need for encoding in different bases, including a standard version of format_integer_in_base makes a lot more sense. We could write format_integer_in_base(15, 16) to get "F" and format_integer_in_base(64, "A23456789TJQK") to get "4K". But note that standard base 64 encoding is not at all the same -- this function encodes starting at LSB while base 64 encodes at word boundaries.</div>

<div><br></div><div><div class="gmail_quote"><div>Finally, note that if you really want to mangle format strings you can do it without changing the library. Just write it this way "{:.16d}".format(arbitrarybase(31)) where you have defined</div>

<div><br></div></div><blockquote style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 40px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">

<div class="gmail_quote"><div>class arbitrarybase:</div></div><div class="gmail_quote"><div>    def __format__(self, format_spec):</div></div><div class="gmail_quote"><div>        return format_integer_in_base(parse format spec etc.) </div>

</div></blockquote></div><div><br clear="all"><font face="arial, helvetica, sans-serif">--- Bruce</font><div><font face="arial, helvetica, sans-serif">Follow me: <a href="http://www.twitter.com/Vroo" target="_blank">http://www.twitter.com/Vroo</a> <a href="http://www.vroospeak.com/" target="_blank">http://www.vroospeak.com</a></font></div>

<div><font face="arial, helvetica, sans-serif"><br></font></div></div>