5

I would like to use mkdir in python.

It has a parameter mode, whose default value is '0o777'.

I know file mode 0777 in Linux. However I don't know what o between 0 and 777 is. What is it?

mkrieger1
  • 14,486
  • 4
  • 43
  • 54
mora
  • 2,027
  • 3
  • 15
  • 30
  • 4
    Nothing a quick tour through [the Python documentation](https://docs.python.org/) would help you solve. And, you should already be able to *guess* what it means (especially if you understand what `0777` is for kind of number, and know about hexadecimal notation). – Some programmer dude Oct 04 '17 at 10:14
  • 1
    @Someprogrammerdude would *not* help you solve (unless you're trying to denounce the Python docs) – mkrieger1 Oct 04 '17 at 10:42
  • @mkrieger1 Yes something like that... :) – Some programmer dude Oct 04 '17 at 12:40

1 Answers1

8

It is a Python friendly way of expressing file permissions, using octal numbers.

>>> 0o777
511
hspandher
  • 14,790
  • 2
  • 28
  • 43
  • 1
    *- But... I still don't know what 'o' between '0' and '777' is. What is it?* – vaultah Oct 04 '17 at 10:17
  • 2
    `o` signifies that the number is an octal number. – hspandher Oct 04 '17 at 10:21
  • @hspandher: thank you for answering it. I will refer to python document for more detail later. – mora Oct 04 '17 at 10:24
  • 1
    @mora Earlier versions of Python didn't use the "o", but that caused problems for some people who tried to interpret decimal numbers with leading zeroes. So it got changed. – PM 2Ring Oct 04 '17 at 10:26
  • 5
    for future readers: in 0o777 the `o` stands for "octal", like the `x` in 0xFF stands for "hexadecimal". In linux file permissions the interpreter assumes that the number given is in octal numbering – Torge Rosendahl Feb 16 '21 at 08:33