Leading 0's syntax error in datetime.date module (Python 3.6)

bartc bc at freeuk.com
Thu May 10 14:31:29 EDT 2018


On 10/05/2018 18:03, Ian Kelly wrote:
> On Thu, May 10, 2018 at 10:36 AM, bartc <bc at freeuk.com> wrote:
>> What, 0O100 instead of 0100? Yeah that's a big improvement...
>>
>> Fortunately octal doesn't get used much.
> 
> The PEP discusses this:
> 
> """
> Proposed syntaxes included things like arbitrary radix prefixes, such
> as 16r100 (256 in hexadecimal), and radix suffixes, similar to the
> 100h assembler-style suffix. The debate on whether the letter "O"
> could be used for octal was intense -- an uppercase "O" looks
> suspiciously similar to a zero in some fonts. Suggestions were made to
> use a "c" (the second letter of "oCtal"), or even to use a "t" for
> "ocTal" and an "n" for "biNary" to go along with the "x" for
> "heXadecimal".
> 
> For the string % operator, "o" was already being used to denote octal.
> Binary formatting is not being added to the % operator because PEP
> 3101 (Advanced String Formatting) already supports binary, %
> formatting will be deprecated in the future.
> 
> At the end of the day, since uppercase "O" can look like a zero and
> uppercase "B" can look like an 8, it was decided that these prefixes
> should be lowercase only, but, like 'r' for raw string, that can be a
> preference or style-guide issue.
> """
> 
> Personally I would have preferred the "t".
> 

	
In my own [syntax] designs, for a long time I used:

   100H   (256) Hex
   100B   (4)   Binary

in addition to decimal. Then I when I switched to 0x for hex (so that I 
could write 0xABC instead of needing to write 0ABCH with a leading 
zero), it was easy to extend that scheme:

   2x100  (4)   Binary
   3x100  (9)   Ternary
   4x100  (16)  Quaternary
   5x100  (25)  etc
   6x100  (36)
   7x100  (49)
   8x100  (64)  Octal
   9x100  (81)
   ...           (Not implemented 11x to 15x, nor 10x or 16x)
   0x100  (256) Hex

I think Ada does something similar for example 2#100#.

However I wouldn't be bothered at having to use for example OCT(377), 
HEX(FF), BIN(1111_1111) or even OCTAL(377), although it's a bit clunky. 
At least it will be obvious; more so than 0o100.

-- 
bartc



More information about the Python-list mailing list