On Feb 6, 2020, at 04:06, Jonathan Fine <[email protected]> wrote:
>
> A NEWBY GOTCHA
> ================
>
> A standard way of writing today's date is 2020-02-06. Let's try this in
> Python, first with Christmas Day, and then for today:
>
> >>> datetime.date(2020, 12, 25)
> datetime.date(2020, 12, 25)
> >>> datetime.date(2020, 02, 06)
> SyntaxError
On the other hand, even if you’re not familiar with any of the languages that
use the C octal format, you are likely to run into it in documentation.
For example, let’s say you want to change a file to not be world-readable or
-executable. You look up os.chmod and, wow, look at all those things you’re
supposed to or together. Is there an easier way? Sure, it’s just calling the
system’s chmod function, and you can man chmod or search online to find a
helpful tutorial blog or look on StackOverflow or ServerFault or SuperUser, and
you’ll quickly find not just a more in-depth explanation, but an example that
does exactly what you want:
chmod(path, 0770)
So, you figure, in Python, it should be just:
os.chmod(path, 0770)
So you put that in a script and you get an error that explains that if this is
meant to be octal you wanted 0o770, if it was meant to be decimal you wanted
770. So you do what it says and add the o and you’re set.
With your change, this instead compiles and runs and sets the mode to 0o1402,
which if you’re lucky you don’t have permissions to do, otherwise it’s now
sticky, execute-only for owner, inaccessible for group, and write-only for
world.
There aren’t mang cases not related to mode values and the os module where this
problem would come up, but I think mode values are common enough, and
unfamiliar enough to newbies that they’re going to search, to be a problem. And
they’re ubiquitously documented in C or shell terms that will give you C-style
octal values, so most people who do search will be misled.
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/DURPQWTWIAQPL2OPVT4SIA7IZ2CQZZN2/
Code of Conduct: http://python.org/psf/codeofconduct/