fchmod()方法改變由 fd 給予數字模式的檔模式。該模式可採取以下值中的一個或按位運算組合:
注意:此方法是 Python2.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!!
上一篇:
Python3檔方法
下一篇:
Python3 os檔目錄的方法
