Python-os-fchown
提供:Dev Guides
Python os.fchown()メソッド
説明
Pythonメソッド* fchown()*は、fdによって指定されたファイルの所有者とグループIDを数値のuidとgidに変更します。 IDの1つを変更しないままにするには、-1に設定します。
注-このメソッドはPython 2.6以降で利用可能です。
構文
以下は* fchown()*メソッドの構文です-
os.fchown(fd, uid, gid);
パラメーター
- fd -これは、所有者IDとグループIDを設定する必要があるファイル記述子です。
- uid -これはファイルに設定される所有者IDです。
- gid -これはファイルに設定されるグループIDです。
戻り値
このメソッドは値を返しません。
例
次の例は、fchown()メソッドの使用法を示しています。
#!/usr/bin/python
import os, sys, stat
# Now open a file "/tmp/foo.txt"
fd = os.open( "/tmp", os.O_RDONLY )
# Set the user Id to 100 for this file.
os.fchown( fd, 100, -1)
# Set the group Id to 50 for this file.
os.fchown( fd, -1, 50)
print "Changed ownership successfully!!"
# Close opened file.
os.close( fd )
上記のプログラムを実行すると、次の結果が生成されます-
Changed ownership successfully!!