Python3 os.lchown() 方法

Python 3 教程 · 2019-02-07 13:29:45

概述

os.lchown() 方法用于更改文件所有者,类似 chown,但是不追踪链接。

只支持在 Unix 下使用。

语法

lchown()方法语法格式如下:

os.lchown(path, uid, gid)

参数

  • path -- 设置权限的文件路径

  • uid -- 所属用户 ID

  • gid -- 所属用户组 ID

返回值

该方法没有返回值。

实例

以下实例演示了 lchown() 方法的使用:

#!/usr/bin/python3

import os, sys

# 打开文件
path = "/var/www/html/foo.txt"
fd = os.open( path, os.O_RDWR|os.O_CREAT )

# 关闭打开的文件
os.close( fd )

# 修改文件权限
# 设置文件所属用户 ID
os.lchown( path, 500, -1)

# 设置文件所属用户组 ID
os.lchown( path, -1, 500)

print ("修改权限成功!!")

执行以上程序输出结果为:

修改权限成功!!

点击查看所有 Python 3 教程 文章: https://www.codercto.com/courses/l/10.html

查看所有标签

Algorithms

Algorithms

Sanjoy Dasgupta、Christos H. Papadimitriou、Umesh Vazirani / McGraw-Hill Education / 2006-10-16 / GBP 30.99

This text, extensively class-tested over a decade at UC Berkeley and UC San Diego, explains the fundamentals of algorithms in a story line that makes the material enjoyable and easy to digest. Emphasi......一起来看看 《Algorithms》 这本书的介绍吧!

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

随机密码生成器
随机密码生成器

多种字符组合密码