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

Chris Angelico rosuav at gmail.com
Thu May 10 15:11:44 EDT 2018


On Fri, May 11, 2018 at 5:04 AM, Jon Ribbens <jon+usenet at unequivocal.eu> wrote:
> On 2018-05-10, Skip Montanaro <skip.montanaro at gmail.com> wrote:
>>> I wonder why someone would take a feature generally agreed to be a
>>> poorly designed feature of C, and incorporate it into a new language.
>>
>> I think you might be looking at a decision made in the late 1980s through a
>> pair of glasses made in 2018.
>>
>> As a C programmer back then I never had a problem with C's octal number
>> notation. People coming from C, C++ or Java to Python at that time would
>> certainly have understood that syntax. It's only in the past 15 years or so
>> that we've seen tons of people coming to Python as a first language for
>> whom leading zero notation would be unfamiliar.
>
> This whole thread is reminding me PHP 2, which would magically treat
> the second parameter of ChMod() as octal, because clearly if weak
> typing is good then *no* typing must be best of all!
>
>   ChMod($filename, 644); // second parameter is actually 420 base 10

Bear in mind that Unix file modes are traditionally written in octal,
because they have no meaning as numbers. They're more like
enumerations, or bitfields. The second parameter happens to be equal
to the base 10 number 420, but that's completely useless. A file mode
of 100644 means something; a file mode of 0x81a4 or 33188 decimal
means nothing. PHP went for crazy magic there, but if the API had been
built such that the "644" is passed as a string, it would have been
completely sane and entirely useful.

ChrisA



More information about the Python-list mailing list