Latest web development tutorials

Python os.fchown () -Methode

Python-Datei (File) Methode Python OS Datei / Verzeichnis - Methoden


Umriss

os.fchown () -Methode verwendet, um das Eigentum an einer Datei zu ändern, ändert diese Funktion eine Benutzer-ID und Gruppen-ID der Datei, um die Datei von der Datei fd aus.

Verfügbar auf Unix.

Grammatik

fchown () -Methode Syntax lautet wie folgt:

os.fchown(fd, uid, gid)

Parameter

  • fd - Dateideskriptor

  • uid - Benutzer - ID - Datei des Eigentümers

  • Benutzergruppe id Besitzer der Datei- gid

Rückgabewert

Dieses Verfahren hat keinen Rückgabewert.

Beispiele

Das folgende Beispiel zeigt fchown () Art der Nutzung:

#!/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 )

Das obige Programm Ausgabe lautet:

修改权限成功!!

Python-Datei (File) Methode Python OS Datei / Verzeichnis - Methoden