[Python-Dev] str with base (original) (raw)

Nick Craig-Wood nick at craig-wood.com
Tue Jan 17 11:05:44 CET 2006


On Mon, Jan 16, 2006 at 11:13:27PM -0500, Raymond Hettinger wrote:

My reason is that I've rolled-my-own more times than I can count but infrequently enough to where it was easier to re-write than to search for the previous use.

Me too! The assymetry is annoying. Its easy to consume base 2..36 integers, but its hard to generate them.

However str() seems far too important to monkey with to me.

I like a method on int that would be great. That keeps all the base conversions in int (either in init or in as_yet_unnamed_method()).

Another suggestion would be to give hex() and oct() another parameter, base, so you'd do hex(123123123, 2). Perhaps a little counter-intuitive, but if you were looking for base conversion functions you'd find hex() pretty quickly and the documentation would mention the other parameter.

-- Nick Craig-Wood <nick at craig-wood.com> -- http://www.craig-wood.com/nick



More information about the Python-Dev mailing list