小白教程
所有教程
关于
Search
172.70.100.217
172.70.100.217
参数设置
贡献
退出
操作
编辑
移动
保护
信息
历史
删除
查看“Python3 os lchown”的源代码
本页内容
上一节:
Python3_os_lchmod
下一节:
Python3_os_link
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{DISPLAYTITLE:os.lchown(path, uid, gid)}}[[Category:python3 os file methods|26]] = Python3 os.lchown() 方法 = [[python3 os file methods|Python3 OS 文件/目录方法]] === 概述 === os.lchown() 方法用于更改文件所有者,类似 chown,但是不追踪链接。 只支持在 Unix 下使用。 === 语法 === '''lchown()'''方法语法格式如下: <sample title="" desc="" lang="python" hererun="1"> os.lchown(path, uid, gid) </sample> === 参数 === * '''path''' -- 设置权限的文件路径 * '''uid''' -- 所属用户 ID * '''gid''' -- 所属用户组 ID === 返回值 === 该方法没有返回值。 == 以下实例演示了 lchown() 方法的使用: <sample title="" desc="" lang="python" hererun="1"> #!/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 ("修改权限成功!!") </sample> 执行以上程序输出结果为: <sample title="" desc="" lang="python" hererun="1"> 修改权限成功!! </sample> [[python3 os file methods|Python3 OS 文件/目录方法]]
返回至“
Python3 os lchown
”。
上一节:
Python3_os_lchmod
下一节:
Python3_os_link