[Python-ideas] Negative hexes

Antoine Pitrou solipsis at pitrou.net
Tue Dec 6 00:10:54 CET 2011


On Tue, 6 Dec 2011 08:19:53 +1000
Nick Coghlan <ncoghlan at gmail.com> wrote:
> On Tue, Dec 6, 2011 at 3:15 AM, Antoine Pitrou <solipsis-xNDA5Wrcr86sTnJN9+BGXg at public.gmane.org> wrote:
> >> That is, currently:
> >>
> >> >>> "{:.4x}".format(31)
> >> Traceback (most recent call last):
> >>   File "<stdin>", line 1, in <module>
> >> ValueError: Precision not allowed in integer format specifier
> >
> > This is so poorly discoverable that I don't think it's worth it.
> > Guido's approach looks sufficient to me.
> 
> I agree the formatting approach is way too obscure, but did you see my
> later suggestion of an "as_twos_complement(bit_length)" conversion
> method on int objects? (we could actually provide a more generic
> version on numbers.Integer as well)

Ah, right. Yes, I think that would be useful, although a shorter name
would be nicer. to_unsigned() perhaps?

Regards

Antoine.





More information about the Python-ideas mailing list