描述
方法fchmod()更改由給出的文件的模式fd到數字模式。該模式可以采用以下值之一或它們的按位或組合 -
注意- 此方法在 Python 2.6 以後可用。
stat.S_ISUID− 執行時設置用戶ID。
stat.S_ISGID− 在執行時設置組 ID。
stat.S_ENFMT− 強製記錄鎖定。
stat.S_ISVTX− 執行後保存文本圖像。
stat.S_IREAD− 所有者閱讀。
stat.S_IWRITE− 所有者編寫。
stat.S_IEXEC− 由所有者執行。
stat.S_IRWXU− 由所有者讀取、寫入和執行。
stat.S_IRUSR− 所有者閱讀。
stat.S_IWUSR− 所有者編寫。
stat.S_IXUSR− 由所有者執行。
stat.S_IRWXG− 按組讀取、寫入和執行。
stat.S_IRGRP− 分組閱讀。
stat.S_IWGRP− 分組寫作。
stat.S_IXGRP− 分組執行。
stat.S_IRWXO− 由他人讀取、寫入和執行。
stat.S_IROTH- 被他人閱讀。
stat.S_IWOTH- 由他人撰寫。
stat.S_IXOTH− 由他人執行。
用法
以下是語法fchmod()方法 -
os.fchmod(fd, mode)
參數
fd- 這是將設置模式的文件描述符。
mode- 這可能采用上述值之一或它們的按位或組合。
返回值
此方法不返回任何值。僅在類 Unix 操作係統上可用。
示例
以下示例顯示了 fchmod() 方法的用法 -
#!/usr/bin/python3
import os, sys, stat
# Now open a file "/tmp/foo.txt"
fd = os.open( "/tmp", os.O_RDONLY )
# Set a file execute by the group.
os.fchmod( fd, stat.S_IXGRP)
# Set a file write by others.
os.fchmod(fd, stat.S_IWOTH)
print ("Changed mode successfully!!")
# Close opened file.
os.close( fd )
結果
當我們運行上述程序時,它會產生以下結果 -
Changed mode successfully!!
相關用法
- Python 3 os.fchown()用法及代碼示例
- Python 3 os.fchdir()用法及代碼示例
- Python 3 os.fstatvfs()用法及代碼示例
- Python 3 os.fdopen()用法及代碼示例
- Python 3 os.fdatasync()用法及代碼示例
- Python 3 os.fsync()用法及代碼示例
- Python 3 os.fpathconf()用法及代碼示例
- Python 3 os.fstat()用法及代碼示例
- Python 3 os.ftruncate()用法及代碼示例
- Python 3 os.minor()用法及代碼示例
- Python 3 os.close()用法及代碼示例
- Python 3 os.unlink()用法及代碼示例
- Python 3 os.major()用法及代碼示例
- Python 3 os.rmdir()用法及代碼示例
- Python 3 os.isatty()用法及代碼示例
- Python 3 os.rename()用法及代碼示例
- Python 3 os.walk()用法及代碼示例
- Python 3 os.renames()用法及代碼示例
- Python 3 os.makedirs()用法及代碼示例
- Python 3 os.utime()用法及代碼示例
注:本文由純淨天空篩選整理自 Python 3 - os.fchmod() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。