8

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
  • 19,194
  • 5
  • 54
  • 65
mora
  • 2,217
  • 4
  • 22
  • 32

1 Answers1

11

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

>>> 0o777
511
hspandher
  • 15,934
  • 2
  • 32
  • 45
  • 2
    *- But... I still don't know what 'o' between '0' and '777' is. What is it?* – vaultah Oct 04 '17 at 10:17
  • 3
    `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
  • 2
    @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
  • 6
    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