Python os.chown() 方法

Python 教程 · 2019-02-03 17:58:59

概述

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

只支持在 Unix 下使用。

语法

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

os.chown(path, uid, gid);

参数

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

  • uid -- 所属用户 ID

  • gid -- 所属用户组 ID

返回值

该方法没有返回值。

实例

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

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

import os, sys

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

print "修改权限成功!!"

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

修改权限成功!!

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

查看所有标签

Hacking Growth

Hacking Growth

Sean Ellis、Morgan Brown / Crown Business / 2017-4-25 / USD 29.00

The definitive playbook by the pioneers of Growth Hacking, one of the hottest business methodologies in Silicon Valley and beyond. It seems hard to believe today, but there was a time when Airbnb w......一起来看看 《Hacking Growth》 这本书的介绍吧!

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

在线压缩/解压 HTML 代码

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具