I naively tried the function chmod from the standard python module called os to change the permission of a file:
Checking in the unix command line (ls -l), I got an unexpected result:
I expected indeed a read-write permission and then 2 read-only. In Python 2.X, you must set the second argument (the mode) to 0644 (note the 0)
In Python 3.X, this statement becomes:
and now, we get the expected answer.
Therefore the mode should be in octal form!! Not obvious from the documentation:
In : os.chmod? Type: builtin_function_or_method String Form:<built-in function chmod> Docstring: chmod(path, mode) Change the access permissions of a file.