描述
Python方法chmod()將路徑模式更改為傳遞的數字模式。該模式可以采用以下值之一或它們的按位或組合 -
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− 由他人執行。
用法
以下是語法chmod()方法 -
os.chmod(path, mode);
參數
path- 這是將設置模式的路徑。
mode- 這可能采用上述值之一或它們的按位或組合。
返回值
此方法不返回任何值。
示例
以下示例顯示了 chmod() 方法的用法 -
#!/usr/bin/python
import os, sys, stat
# Assuming /tmp/foo.txt exists, Set a file execute by the group.
os.chmod("/tmp/foo.txt", stat.S_IXGRP)
# Set a file write by others.
os.chmod("/tmp/foo.txt", stat.S_IWOTH)
print "Changed mode successfully!!"
當我們運行上麵的程序時,它會產生以下結果 -
Changed mode successfully!!
相關用法
- Python os.chmod用法及代碼示例
- Python os.chflags()用法及代碼示例
- Python os.chroot()用法及代碼示例
- Python os.chdir()用法及代碼示例
- Python os.chown()用法及代碼示例
- Python os.closerange()用法及代碼示例
- Python os.ctermid()用法及代碼示例
- Python os.close()用法及代碼示例
- Python os.cpu_count()用法及代碼示例
- Python os.confstr()用法及代碼示例
- Python os.path.normcase()用法及代碼示例
- Python os.read()用法及代碼示例
- Python os.DirEntry.inode()用法及代碼示例
- Python os.set_blocking()用法及代碼示例
- Python os.getresgid() and os.setresgid()用法及代碼示例
- Python os.pathconf()用法及代碼示例
- Python os.WCOREDUMP()用法及代碼示例
- Python os.fork()用法及代碼示例
- Python os.mkfifo()用法及代碼示例
- Python os.tcsetpgrp()用法及代碼示例
注:本文由純淨天空篩選整理自 Python os.chmod() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。