Python os.fchmod() Method
Example
Change the mode of a file to "Read, write, and execute by group":
# Import os Library
import os
# open a file
fd = os.open( "test.txt", os.O_RDONLY)
# Change the mode of the file
os.fchmod(fd,stat.S_IRWXG)
#close file
os.close(fd)
Definition and Usage
The os.fchmod()
method is used to change the mode of a file
to the specified numeric mode.
Modes are file system permissions given to a user or a group to access a file.
Tip: This method is equivalent to
os.chmod(fd, mode)
.
Note: Available only on UNIX platforms.
Syntax
os.fchmod(fd, mode)
Parameter Values
Parameter | Description |
---|---|
fd | Required. A file descriptor |
mode | Required. The mode to be set. Can be one of the following:stat.S_ISUID : Set user ID on execution stat.S_ISGID : Set group ID on execution stat.S_ENFMT : Record locking enforced stat.S_ISVTX : Save text image after execution stat.S_IREAD : Read by owner stat.S_IWRITE : Write by owner stat.S_IEXEC : Execute by owner stat.S_IRWXU : Read, write, and execute by owner stat.S_IRUSR : Read by owner stat.S_IWUSR : Write by owner stat.S_IXUSR : Execute by owner stat.S_IRWXG : Read, write, and execute by group stat.S_IRGRP : Read by group stat.S_IWGRP : Write by group stat.S_IXGRP : Execute by group stat.S_IRWXO : Read, write, and execute by others stat.S_IROTH : Read by others stat.S_IWOTH : Write by others stat.S_IXOTH : Execute by others |
Technical Details
Return Value: | None |
---|---|
Python Version: | 2.6 |