Python os.fchown() 方法
概述
os.fchown() 方法用於修改一個檔的所有權,這個函數修改一個檔的用戶ID和用戶組ID,該檔由檔描述符fd指定。
Unix上可用。
語法
fchown()方法語法格式如下:
os.fchown(fd, uid, gid)
參數
fd -- 檔描述符
uid -- 檔所有者的用戶id
gid -- 檔所有者的用戶組id
返回值
該方法沒有返回值。
實例
以下實例演示了 fchown() 方法的使用:
#!/usr/bin/python # -*- coding: UTF-8 -*- import os, sys, stat # 打開檔 "/tmp/foo.txt" fd = os.open( "/tmp", os.O_RDONLY ) # 設置檔的用戶 id 為 100 os.fchown( fd, 100, -1) # 設置檔的用戶組 id 為 100 os.fchown( fd, -1, 50) print "修改許可權成功!!" # 關閉檔 os.close( fd )
執行以上程式輸出結果為:
修改許可權成功!!