Latest web development tutorials

Python3 os.fchmod () method

Python3 OS file / directory methods Python3 OS file / directory methods


Outline

os.fchmod () method is used to change the access permissions of a file, the file specified by the parameter fd, the parameter mode is file access permissions on Unix.

Available on Unix.

grammar

fchmod () method syntax is as follows:

os.fchmod(fd, mode);

parameter

  • fd - file descriptor

  • mode - can be one or more components, multiple use "|" separated:

    • stat.S_ISUID: set UID bit

    • stat.S_ISGID: set group ID bits

    • stat.S_ENFMT: system file locking enforcement action

    • stat.S_ISVTX: After the save text and images

    • stat.S_IREAD: read access for the owner

    • stat.S_IWRITE: write permissions for the owner

    • stat.S_IEXEC: execute permissions for the owner of

    • stat.S_IRWXU: For the owner to read, write, and execute permissions

    • stat.S_IRUSR: read access for the owner

    • stat.S_IWUSR: write permissions for the owner

    • stat.S_IXUSR: execute permissions for the owner of

    • stat.S_IRWXG: for the same group of people permission to perform read and write

    • stat.S_IRGRP: For the same group read access

    • stat.S_IWGRP: write permissions for the same group

    • stat.S_IXGRP: execute permissions for the same group of

    • stat.S_IRWXO: read and write permissions for the other groups performed

    • stat.S_IROTH: read access for other groups

    • stat.S_IWOTH: write privileges for other groups

    • stat.S_IXOTH: permission to other groups by the

return value

This method has no return value.

Examples

The following example demonstrates fchmod () method of use:

#!/usr/bin/python3

import os, sys, stat

# 打开文件 "/tmp/foo.txt"
fd = os.open( "/tmp", os.O_RDONLY )

# 设置文件可通过组执行

os.fchmod( fd, stat.S_IXGRP)

# 设置文件可被其他用户写入
os.fchmod(fd, stat.S_IWOTH)

print ("修改权限成功!!")

# 关闭文件
os.close( fd )

The above program output is:

修改权限成功!!

Python3 OS file / directory methods Python3 OS file / directory methods