[Python-Dev] str with base

Bob Ippolito bob at redivi.com
Tue Jan 17 11:44:05 CET 2006


On Jan 17, 2006, at 2:36 AM, Ian Bicking wrote:

> Bob Ippolito wrote:
>> On Jan 16, 2006, at 9:12 PM, Andrew Bennetts wrote:
>>> On Mon, Jan 16, 2006 at 11:54:05PM -0500, Raymond Hettinger wrote:
>>> [...]
>>>
>>>> That suggests that it would be better to simply add an int method:
>>>>
>>>>     x.convert_to_base(7)
>>>
>>> This seems clear and simple to me.  I like it.  I strongly  
>>> suspect  the "bright
>>> beginners" Alex is interested in would have no trouble using it  
>>> or  finding it.
>> I don't know about that, all of the methods that int and long   
>> currently have are __special__.  They'd really need to start with   
>> Python 2.5 (assuming int/long grow "public methods" in 2.5) to  
>> even  think to look there.  A format code or a built-in would be  
>> more  likely to be found, since that's how you convert integers to  
>> hex and  oct string representations with current Python.
>
> How about just stuffing some function in the math module?   
> Everything in that module works on floats, but it seems incidental  
> to me; I'm pretty sure I've even looked in that module for such a  
> function before.  But it's such an obscure need that only comes up  
> in the kind of algorithms students write, that it just seems odd  
> and unnecessary to put it in str() which is *so* much more general  
> than int() is.

I want binary all the time when I'm dealing with bitflags and such.   
Of course, I'm trained to be able to read bits in hex format, but it  
would be nicer to see the flags as-is.  Even worse when you have to  
deal with some kind of file format where fields are N bits long,  
where N is not a multiple of 8.

-bob



More information about the Python-Dev mailing list