[TriZPUG] Python Wart?

Chris Rossi chris at archimedeanco.com
Thu Mar 19 02:19:59 CET 2015


I agree with Calloway that that probably ought to be the default.

Chris


On Wed, Mar 18, 2015 at 9:13 PM, Kevin Howell <kevin at kahowell.net> wrote:

> You can use int('0xAA', 0) for this. From the documentation: "Base 0
> means to interpret exactly as a code literal, so that the actual base is
> 2, 8, 10, or 16". https://docs.python.org/3/library/functions.html#int
>
> >>> int('10', 0)
> 10
> >>> int('0xAA', 0)
> 170
>
> Kevin Howell | kevin at kahowell.net | http://www.kahowell.net
> On 03/18/2015 07:36 PM, Chris Calloway wrote:
> > >>> 10
> > 10
> > >>> int('10')
> > 10
> > >>> 0xAA
> > 170
> > >>> int('0xAA')
> > Traceback (most recent call last):
> >   File "<stdin>", line 1, in <module>
> > ValueError: invalid literal for int() with base 10: '0xAA'
> > >>> int('0xAA', 16)
> > 170
> > >>>
> >
> > I have to specify the radix for perfectly valid literal int strings
> > that aren't base 10? Boo. Int should parse literals in strings without
> > hints just like the interpreter does.
> >
>
> _______________________________________________
> TriZPUG mailing list
> TriZPUG at python.org
> https://mail.python.org/mailman/listinfo/trizpug
> http://trizpug.org is the Triangle Zope and Python Users Group
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/trizpug/attachments/20150318/aecbb417/attachment.html>


More information about the TriZPUG mailing list