[Python-ideas] Different bases format specification

T.B. bauertomer at gmail.com
Sat Dec 3 04:16:00 CET 2011


On 2011-12-03 03:31, Nick Coghlan wrote:
> On Sat, Dec 3, 2011 at 10:12 AM, T.B.<bauertomer at gmail.com>  wrote:
>> I suggest using the precision field in the format specification for integers
>> for that.
>
> Supporting arbitrary bases for string formatting has been discussed
> and rejected in the past (both in the context of PEP 3101's
> introduction of new string formatting and on other occasions).
>
> Nobody has ever produced convincing use cases for natively supporting
> formatting with bases other than binary, octal, decimal and
> hexadecimal. Accordingly, those 4 are supported explicitly via the
> 'b', 'o', 'd' and 'x'/'X' formatting codes, while other formats still
> require an explicit conversion function.

For weird math scenarios I know there are already many modules and 
packages. But what about ternary? 
en.wikipedia.org/wiki/Ternary_numeral_system has some points that 
include that base 9 and 27 are used [no citation].

> As for "Why Not?"
>
> 1. 'd' stands for decimal. If support for arbitrary bases were added,
> it would need to be as a separate format code (e.g. 'i' for integer)
>
> 2. The explicit 'b', 'o' and 'x' codes are related to integer literal
> notation (0b10, 0o777, 0x1F), not to the second argument to int()
>
That one reason I wrote: "It might be a nice mnemonic using 'b' instead, 
standing for 'base'. Then the default base will be 2."
Anyway, I think there should be 'B' and 'O' presentation types, that
will be used for outputting '0B' and '0O' prefixes.

Thanks for your reply,
TB



More information about the Python-ideas mailing list