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://www.codercto.com/courses/l/8.html

查看所有标签

Numerical Methods and Methods of Approximation in Science and En

Numerical Methods and Methods of Approximation in Science and En

Karan Surana / CRC Press / 2018-10-31

ABOUT THIS BOOK Numerical Methods and Methods of Approximation in Science and Engineering prepares students and other readers for advanced studies involving applied numerical and computational anal......一起来看看 《Numerical Methods and Methods of Approximation in Science and En》 这本书的介绍吧!

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

在线压缩/解压 CSS 代码

在线进制转换器
在线进制转换器

各进制数互转换器

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具