os.chown(path, uid, gid)
path -- 這是它的所有者ID和組ID,需要被設定的路徑。
uid -- 這是要設定的檔案所有者ID。
gid -- 這是要設定的檔案組ID。
#!/usr/bin/python3 import os, sys # Assuming /tmp/foo.txt exists. # To set owner ID 100 following has to be done. os.chown("/tmp/foo.txt", 100, -1) print ("Changed ownership successfully!!")
Changed ownership successfully!!