Python os.chmod() Method
Example
Change the mode of path to the numeric mode :
#Import os and stat Library
import os,stat
#Change the mode of path
os.chmod("/tmp/test.txt", stat.S_IWRITE)
Definition and Usage
The os.chmod()
method is used to change the mode of path to the numeric mode.
Note: Available on UNIX and WINDOWS platforms.
Syntax
os.chmod(path, mode, dir_fd, follow_symlinks)
Parameter Values
Parameter | Description |
---|---|
path | Required. A file path to set the flag |
mode | Required. One or more stat module constants which might be in combination (bitwise OR), stat.S_ISUID - Set user ID on executionstat.S_ISGID - Set group ID on executionstat.S_ENFMT - Record locking enforcedstat.S_ISVTX - Save text image after executionstat.S_IREAD - Read by ownerstat.S_IWRITE - Write by ownerstat.S_IEXEC - Execute by ownerstat.S_IRWXU - Read, write, and execute by ownerstat.S_IRUSR - Read by ownerstat.S_IWUSR - Write by ownerstat.S_IXUSR - Execute by ownerstat.S_IRWXG - Read, write, and execute by groupstat.S_IRGRP - Read by groupstat.S_IWGRP - Write by groupstat.S_IXGRP - Execute by groupstat.S_IRWXO - Read, write, and execute by othersstat.S_IROTH - Read by othersstat.S_IWOTH - Write by othersstat.S_IXOTH - Execute by others |
dir_fd | Optional. If None, the path will be relative to the directory. None is default |
follow_symlinks | Optional. Default value is TRUE. Set it to FALSE to not follow symlinks |
Technical Details
Return Value: | None |
---|---|
Python Version: | 2.6 |
Change Log: | 3.3: Support for specifying path as an open file descriptor, and added the
dir_fd and follow_symlinks parameters. 3.6: Accepts a path-like object. |