Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python os.lchown() method

Python os.lchown() method

Python File methods Python OS file/directory methods


Overview

The os.lchown() method changes the file owner, similar to chown, but without following links.

Only supported on Unix.

Syntax

The **lchown()** method syntax is as follows:



os.lchown(path, uid, gid)

Parameters

Return Value

This method has no return value.

Example

The following example demonstrates the use of the lchown() method:



#!/usr/bin/python

# -*- coding: UTF-8 -*-



import os, sys



# Open file

path = "/var/www/html/foo.txt"

fd = os.open( path, os.O_RDWR|os.O_CREAT )



# Close open files

os.close( fd )



# Change file permissions

# Set file owner user ID

os.lchown( path, 500, -1)



# Set file owner group ID

os.lchown( path, -1, 500)



print "修改权限成功!!"

The output of the above program is:



修改权限成功!!

Python File methods Python OS file/directory methods