Python os.fchown() 方法

Python 教程 · 2019-02-03 19:57:58

概述

os.fchown() 方法用于修改一个文件的所有权,这个函数修改一个文件的用户ID和用户组ID,该文件由文件描述符fd指定。

Unix上可用。

语法

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

os.fchown(fd, uid, gid)

参数

  • fd -- 文件描述符

  • uid -- 文件所有者的用户id

  • gid -- 文件所有者的用户组id

返回值

该方法没有返回值。

实例

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

#!/usr/bin/python
# -*- coding: UTF-8 -*-

import os, sys, stat

# 打开文件 "/tmp/foo.txt"
fd = os.open( "/tmp", os.O_RDONLY )

# 设置文件的用户 id 为 100
os.fchown( fd, 100, -1)

# 设置文件的用户组 id 为 100
os.fchown( fd, -1, 50)


print "修改权限成功!!"

# 关闭文件
os.close( fd )

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

修改权限成功!!

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

查看所有标签

Spring Into HTML and CSS

Spring Into HTML and CSS

Molly E. Holzschlag / Addison-Wesley Professional / 2005-5-2 / USD 34.99

The fastest route to true HTML/CSS mastery! Need to build a web site? Or update one? Or just create some effective new web content? Maybe you just need to update your skills, do the job better. Welco......一起来看看 《Spring Into HTML and CSS》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

html转js在线工具
html转js在线工具

html转js在线工具

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具