Python3 os.chown() 方法

Python 3 教程 · 2019-02-07 08:11:26

概述

os.chown() 方法用于更改文件所有者,如果不修改可以设置为 -1, 你需要超级用户权限来执行权限修改操作。

只支持在 Unix 下使用。

语法

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

os.chown(path, uid, gid);

参数

  • path -- 设置权限的文件路径

  • uid -- 所属用户 ID

  • gid -- 所属用户组 ID

返回值

该方法没有返回值。

实例

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

#!/usr/bin/python3

import os, sys

# 假定 /tmp/foo.txt 文件存在.
# 设置所有者 ID 为 100 
os.chown("/tmp/foo.txt", 100, -1)

print ("修改权限成功!!")

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

修改权限成功!!

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

查看所有标签

Learning JavaScript

Learning JavaScript

Shelley Powers / Oreilly & Associates Inc / 2006-10-17 / $29.99

As web browsers have become more capable and standards compliant, JavaScript has grown in prominence. JavaScript lets designers add sparkle and life to web pages, while more complex JavaScript has led......一起来看看 《Learning JavaScript》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具