- Given a file descriptor, the function fchmod() of os module in Python changes the permissions of the associated file. To change file permissions using only a file path, instead of a file descriptor the os.chmod() function to be used.
fd - File descriptor. Note that this is not the file object as returned by the built-in function open(). It has to be a descriptor as returned by the function like os.open().
mode - One or more file permissions bitwise ORed
# Example Python program that changes the permissions
# File for which the permissions need to be changed
# Change the file permissions
Though the above program does not print anything issuing an ls -l on the test.txt prints the following, that shows the new file permissions for test.txt.
|mymac:PEX usr1$ ls -l test.txt
-rwxr----x 1 root wheel 0 Mar 30 13:59 test.txt