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
Head First Design Patterns
Elisabeth Freeman、Eric Freeman、Bert Bates、Kathy Sierra、Elisabeth Robson / O'Reilly Media / 2004-11-1 / USD 49.99
You're not alone. At any given moment, somewhere in the world someone struggles with the same software design problems you have. You know you don't want to reinvent the wheel (or worse, a flat tire),......一起来看看 《Head First Design Patterns》 这本书的介绍吧!