小白教程
所有教程
关于
Search
172.70.80.109
172.70.80.109
参数设置
贡献
退出
操作
编辑
移动
保护
信息
历史
删除
查看“Python3 os fchown”的源代码
本页内容
上一节:
Python3_os_fchmod
下一节:
Python3_os_fdatasync
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{DISPLAYTITLE:os.fchown(fd, uid, gid)}}[[Category:python3 os file methods|13]] = Python3 os.fchown() 方法 = [[python3 os file methods|Python3 OS 文件/目录方法]] === 概述 === os.fchown() 方法用于修改一个文件的所有权,这个函数修改一个文件的用户ID和用户组ID,该文件由文件描述符fd指定。 Unix上可用。 === 语法 === '''fchown()'''方法语法格式如下: <sample title="" desc="" lang="python" hererun="1"> os.fchown(fd, uid, gid) </sample> === 参数 === * '''fd''' -- 文件描述符 * '''uid''' -- 文件所有者的用户id * '''gid''' -- 文件所有者的用户组id === 返回值 === 该方法没有返回值。 == 以下实例演示了 fchown() 方法的使用: == 实例(Python 3.0+) == <sample title="" desc="" lang="python" hererun="1"> #!/usr/bin/python3 import os, sys, stat # 打开文件 "/tmp/foo.txt" fd = os.open( "/tmp", os.O_RDONLY ) # 设置文件的用户 id 为 100 os.fchown( fd, 100, -1) # 设置文件的用户组 id 为 50 os.fchown( fd, -1, 50) print ("修改权限成功!!") # 关闭文件 os.close( fd ) </sample> 执行以上程序输出结果为: <sample title="" desc="" lang="python" hererun="1"> 修改权限成功!! </sample> [[python3 os file methods|Python3 OS 文件/目录方法]]
返回至“
Python3 os fchown
”。
上一节:
Python3_os_fchmod
下一节:
Python3_os_fdatasync